|
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
Try it yourself, you may find it is not as difficult as you think!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I have 2 tables in the same database.
tblAircraft - ACID, ACName
tblMaster - MasterID, ACID, and many others that are not relevant to my question.
tblAircraft is a lookup table with all the aircraft listed. tblMaster is the main table and holds all the detail information.
I have a DataGridView that has several columns. Column 1 is a combobox column that has the ACName from tblAircraft. The rest of the columns are textbox columns with data from tblMaster. My application works as far as displaying all the data and I can use a dataadapter update command to update tblMaster (good) and the other datasource updates tblAircraft (bad) with the DataGridView. My problem is that I want ACID in tblMaster to be updated with the ACID from the combobox. Of course it won't because it belongs to the datasource for tblAircraft. How can I use the selection in the combo box to update the tblMaster table along with the other fields in the DataGridView?
I have spent hours and hours trying to figure this out. I hope my explanation is clear. Thank you in advance for any help you can provide.
<pre>
Private Sub cboAC_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cboAC.SelectionChangeCommitted
dsACGrid = LoadDataSet()
'Refreshes DataGridView
If dgvTasks.ColumnCount > 0 Then
For i As Integer = 0 To dgvTasks.ColumnCount - 1
dgvTasks.Columns.RemoveAt(0)
Next
End If
'Connection obj to database
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"
Dim cbColumn As New DataGridViewComboBoxColumn With
{
.DataPropertyName = "ACName",
.DataSource = dsACGrid.Tables(1),
.DisplayMember = "ACName",
.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing,
.Name = "cbColumn",
.HeaderText = "Aircraft",
.SortMode = DataGridViewColumnSortMode.NotSortable,
.ValueMember = "ACName"
}
dgvTasks.Columns.Insert(0, cbColumn)
Dim GSTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "GSTask", .HeaderText = "Gen Spt Task"}
Dim LCOMTask As New DataGridViewTextBoxColumn With {.DataPropertyName = "LCOMTask", .HeaderText = "LCOM Task"}
Dim AFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "AFSC", .HeaderText = "AFSC"}
Dim ReqSkill As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqSkill", .HeaderText = "Req Skill"}
Dim ReqGrade As New DataGridViewTextBoxColumn With {.DataPropertyName = "ReqGrade", .HeaderText = "Req Grade"}
Dim NotesQuestions As New DataGridViewTextBoxColumn With {.DataPropertyName = "NotesQuestions", .HeaderText = "Notes/Questions"}
Dim AvgTimeHours As New DataGridViewTextBoxColumn With {.DataPropertyName = "AvgTimeHours", .HeaderText = "Avg Time-Hours"}
Dim CrewSizeMin As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMin", .HeaderText = "Crew Size Min"}
Dim CrewSizeMax As New DataGridViewTextBoxColumn With {.DataPropertyName = "CrewSizeMax", .HeaderText = "Crew Size Max"}
Dim Manhours As New DataGridViewTextBoxColumn With {.DataPropertyName = "Manhours", .HeaderText = "Manhours"}
Dim FreqQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqQty", .HeaderText = "Freq Qty"}
Dim FreqRate As New DataGridViewTextBoxColumn With {.DataPropertyName = "FreqRate", .HeaderText = "Freq Rate"}
Dim PAFSC As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSC", .HeaderText = "PAFSC"}
Dim PAFSCQty As New DataGridViewTextBoxColumn With {.DataPropertyName = "PAFSCQty", .HeaderText = "PAFSC Qty"}
Dim AltAFSC1 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1", .HeaderText = "Alt AFSC1"}
Dim AltAFSC1Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC1Qty", .HeaderText = "Alt AFSC1 Qty"}
Dim AltAFSC2 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2", .HeaderText = "Alt AFSC2"}
Dim AltAFSC2Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC2Qty", .HeaderText = "Alt AFSC2 Qty"}
Dim AltAFSC3 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3", .HeaderText = "Alt AFSC3"}
Dim AltAFSC3Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC3Qty", .HeaderText = "Alt AFSC3 Qty"}
Dim AltAFSC4 As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4", .HeaderText = "Alt AFSC4"}
Dim AltAFSC4Qty As New DataGridViewTextBoxColumn With {.DataPropertyName = "AltAFSC4Qty", .HeaderText = "Alt AFSC4 Qty"}
Dim ACSelected As New DataGridViewCheckBoxColumn With {.DataPropertyName = "ACSelected", .HeaderText = "Selected"}
With dgvTasks
.AutoGenerateColumns = False
.Columns.AddRange(New DataGridViewColumn() {GSTask, LCOMTask, AFSC, ReqSkill, ReqGrade,
NotesQuestions, AvgTimeHours, CrewSizeMin, CrewSizeMax, Manhours, FreqQty, FreqRate,
PAFSC, PAFSCQty, AltAFSC1, AltAFSC1Qty, AltAFSC2, AltAFSC2Qty,
AltAFSC3, AltAFSC3Qty, AltAFSC4, AltAFSC4Qty, ACSelected})
End With
'Bind the dataset after all operation to the datagrid
dgvTasks.DataSource = dsACGrid.Tables(0)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"
'Loads dropdown for aircraft type
Dim strSQL As String = "Select * from tblAircraft"
Dim daAC As OleDbDataAdapter = New OleDbDataAdapter(strSQL, Conn)
daAC.Fill(dsAC, "tblAircaft")
Dim dr As DataRow = dsAC.Tables(0).NewRow()
dr("ACName") = ""
dsAC.Tables(0).Rows.InsertAt(dr, 0)
Using cmd As New OleDbCommand(strSQL, Conn)
With cboAC
.DataSource = dsAC.Tables(0)
.DisplayMember = "ACName"
.ValueMember = "ACName"
End With
End Using
dsAC.Tables.RemoveAt(0)
End Sub
Private Function LoadDataSet() As DataSet
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\SupportGeneral.accdb"
'This code refreshes the datasets and data tables.
If dtACGrid.Rows.Count > 0 Then
dsACGrid.Tables.RemoveAt(0)
dtACGrid.Clear()
End If
If dtAircraft.Rows.Count > 0 Then
dsACGrid.Tables.RemoveAt(0)
dtAircraft.Clear()
End If
dsACGrid.Tables.Add(dtACGrid)
'Load Master table
strACGrid = "select * from tblMaster where ACName = '" & cboAC.SelectedValue & "'"
daACGrid = New OleDbDataAdapter(strACGrid, Conn)
cbACGrid = New OleDbCommandBuilder(daACGrid)
cbACGrid.QuotePrefix = "["
cbACGrid.QuoteSuffix = "]"
daACGrid.Fill(dtACGrid)
dsACGrid.Tables.Add(dtAircraft)
'Load Aircraft table
strACGrid = "select * from tblAircraft"
daACGrid = New OleDbDataAdapter(strACGrid, Conn)
cbACGrid = New OleDbCommandBuilder(daACGrid)
cbACGrid.QuotePrefix = "["
cbACGrid.QuoteSuffix = "]"
daACGrid.Fill(dtAircraft)
Return dsACGrid
End Function
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
daACGrid.Update(dtACGrid)
Me.Close()
End Sub
End Class
</pre>
|
|
|
|
|
This is a design issue, the way most of us settle it is not to allow editing in a complex (more than 1 or 2 editable fields) DGV.
I make the user doubleclick on the row that want to edit and pop a dialog box. An Add button allows you to pop an empty dialog box for entry.
Then save the AC details getting the ID as a return value, then save the detail record with the ACID.
Better still is to break your form into 2 forms, a list of aircraft and an Aircraft form with 2 areas, Aircraft details as the parent (single record) area with the details in the grid. User doubleclicks on the aircraft in the list form and the aircraft form displays, then the user maintains the Aircraft details in the top panel and doubleclicks the detail row to maintain.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I am creating a some PDF and Word docs on the fly, using itextsharp and an Aspose component for each respectively, importing some images. The raw images are 1000x1000 px, which is way too large - I need to fit two per page, above each other (and some text). I find they have to be no bigger than 300x300 for my requirements.
I can take two approaches:
1) import the images as are, and display them at 300x300 using appropriate object properties
2) re-size the images first to 300x300 then import these and display them at that size.
Approach 1) works beautifully. But with 14 such images the final product is over about 14MB - somewhat large for emailing.
Approach 2) works... but the image quality is lousy. Below is my code for re-sizing the images - my questions is:
Can this code be improved - and how come the docs can re-size them on the fly and retain such high quality, but this code is so bad?
The images are PNG's.
Private Function ResizePlayoutImage(ByVal sFile As String) As Boolean
Try
Dim FullSizeImage As System.Drawing.Image
FullSizeImage = System.Drawing.Image.FromFile(xmlPath & "Playout_images\\" & sFile)
If FullSizeImage.Width = 300 Then
FullSizeImage.Dispose()
If File.Exists(xmlPath & "Edited_images\\" & sFile) Then File.Delete(xmlPath & "Edited_images\\" & sFile)
File.Copy(xmlPath & "Playout_images\\" & sFile, xmlPath & "Edited_images\\" & sFile)
Else
Dim tmp As Bitmap
Dim gX As System.Drawing.Graphics
tmp = New Bitmap(300, 300)
gX = System.Drawing.Graphics.FromImage(tmp)
gX.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
gX.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
gX.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
gX.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality
gX.DrawImage(FullSizeImage, 0, 0, 300, 300)
If File.Exists(xmlPath & "Edited_images\\" & sFile) Then File.Delete(xmlPath & "Edited_images\\" & sFile)
tmp.Save(xmlPath & "Edited_images\\" & sFile, System.Drawing.Imaging.ImageFormat.Png)
tmp.Dispose()
gX.Dispose()
FullSizeImage.Dispose()
End If
Return True
Catch ex As Exception
adp.WriteLog("ResizePlayoutImage", ex.Message & vbCrLf & sFile)
Return False
End Try
End Function
(PS there's something not quite right in the editor here, CP - NB I have to add a \ before any quotes or it messes up the display - but of course the code doesn't need that.)
modified 3-Oct-17 8:58am.
|
|
|
|
|
A_Griffin wrote: something not quite right in the editor here, CP - NB I have to add a \ Most likely because you have use language neutral <pre> tags round your code block. Use the code button to select the appropriate programming language.
|
|
|
|
|
|
some one please help me in designing database tables to record financial transactions in a central university in india. we are using double entry system. database shall be used for in-house development team.
M KAMIL
|
|
|
|
|
Have a look through these data structures
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi. I am developing a staff information form. How to retrieve staff information from Access Database after staff login? Which mean who login then it will display his information at second form.
Examples, staff A login, at the next form it will display staff A details. And staff B login it will display Staff B information.
|
|
|
|
|
1. Create a connection to the database.
2. Run a query against the correct tables.
3. Read the results of the query.
4. Display the results in a form.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
with rsOrder
.ActiveConnection = Conn
.ActiveConnection = sConnString
.CursorLocation = (adUseClient)
.CursorType = (adOpenStatic)
.LockType = (adLockBatchOptimistic)
'Conn.Open()
Conn.Close()
End With
If rsOrder.EOF Then (error at this line I dont know how I can use EOF in vb.net for windows application)
ValidateOrderID = Nothing
iCount = 0
Else
ValidateOrderID = rsOrder
iCount = 1
End If
|
|
|
|
|
If you're moving to .NET, you should be looking to replace the ancient ADODB with the built-in ADO.NET[^] instead. It will take some work to upgrade, but it will make things a lot easier in the long run.
As to the error, I suspect it might have something to do with the fact that you've closed the database connection before you try to read the query results.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I check the connection but is not closed. I tried to avoid COM exception but did not get any success. I added few References also according to google search but nothing is working.
|
|
|
|
|
|
I need to specify a variable or text box in a SQL where clause. I am having a very difficult time replacing ‘IN PRODUCTION’ shown in the below code with a variable or test box. My desire is to use a variable, but is that is not possible a text box will do.
Below is the section of code with the WHERE clause. The query currently returns every item perfectly where the Status equals "IN PRODUCTION" What I would like to do is use a variable so that the same query can be used based on user selection.
FROM tbl_Switches WHERE Status = 'IN PRODUCTION' ORDER BY Node", cs)
|
|
|
|
|
What you need to look at is the SQL Parameters, to support parameterized queries. That way you can generate the SQL queries that look like this,
SELECT * FROM tble_Switches WHERE Status = @p1 ORDER BY Node
Now you will pass a parameter @p1 , which comes from a user input (combobox, or anything of your choice) and then you will finally get the records for that status.
Using SQLParameters with VB.NET/C#
SqlCommand.Parameters Property (System.Data.SqlClient)
Never try to build up a query by concatenation. You will expose the query to SQL Injection and that will only hurt; badly. SQL injection - Wikipedia.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
how can i add user-agent to vlc player when playing rtsp server.
Set vlcControl = Controls.Add("VideoLAN.VLCPlugin.2", "vlcControl" & i)
vlcControl.Height = 6000
vlcControl.Width = 5000
x = Int(Rnd * 60)
Set vlcPlayer = vlcControl.object
vlcControl.Visible = True
ReqVideo = Text2.Text
vlcControl.object.playlist.Add ((ReqVideo))
vlcControl.object.playlist.play
vlcPlayer.audio.volume = 100
i will really appreciate it if anybody can tell me how i can add custom user-agents to this.
|
|
|
|
|
Hi,
In VB forms, I want to do a search of an XLSX for a part number and have the cell line shown in a textbox.
So basically I will make a textbox, type in the part number, click the search button, it will search the xlsx for the part number and show the part number in another textbox. I will probably expand on this showing the description of the part but for now I am just trying to do this (Not a message box)
Similar to the code I provided.
I know the code just reads the line given, but it is simple and that is what I am looking for, for the search.
I have been searching for this method and can't seem to find it.
(I keep seeing datagrid and datasource)
Thank-you
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Dim APP As New Excel.Application
Dim worksheet As Excel.Worksheet
Dim workbook As Excel.Workbook
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
workbook = APP.Workbooks.Open("C:\MAIN PARTS LIST\temp.xlsx")
worksheet = workbook.Worksheets("sheet1")
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
TextBox1.Text = worksheet.Cells(1, 1).Value
TextBox2.Text = worksheet.Cells(1, 2).Value
If TextBox1.Text = ("RENT") Then
TextBox4.Text = "TADA"
Else
TextBox4.Text = "NOPE"
End If
workbook.Close()
APP.Quit()
End Sub
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs)
End Sub
Private Sub TextBox4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox4.TextChanged
End Sub
Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End Class
|
|
|
|
|
You just need to create a loop that tests the content of each cell in the range to see if it contains the value you are looking for.
|
|
|
|
|
If the data is tructured into regular columns - e.g column 1 is part number, column 2 is description etc, you will get much better performance if you open a data connection to the worksheet and use a query to retrieve the data.
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Thank-you both, but code examples would help me more understand
|
|
|
|
|
how do i link opengl in vb2017 ?
i have some experiance whit opengl in freebasic
|
|
|
|
|
this is a try at GP
i have this working in liberty/just basic
GP what :
from tabel or plot to formula
GP how :
1 : write some random formula's
2 : calculate output of formula's
3 : sort formula's on error
4 : mix the best in child's
5 : mutate some child's
6 : if best.error > whised and generation < max then goto 2
i got so far as this :
[code]
'' bluatigro 4 sept 2017
'' genetic programming module
Module Module1
Public Const gp_add As String = "[ + # # ]"
Public Const gp_sub As String = "[ - # # ]"
Public Const gp_mul As String = "[ * # # ]"
Public Const gp_div As String = "[ / # # ]"
Public Const gp_sqrt As String = "[ sqrt # # ]"
Public Class GeneProg
Private genes As Collection
Private Enum numMode As Integer
OnlyInputs = 0
AsDouble = 1
AsInteger = 2
End Enum
Private gpstate As numMode
Public Sub New()
gpstate = numMode.OnlyInputs
End Sub
Public Sub use(gen As String)
genes.Add(gen)
End Sub
Public Function run(prog As String) As String
While InStr(prog, "]") <> 0
Dim eind As Int16 = InStr(prog, "]")
Dim begin As Int16 = eind
While Mid(prog, begin, 1) <> "["
begin -= 1
End While
Dim part As String = Mid(prog _
, begin, eind - begin + 1)
Dim q() As String = Split(part)
Dim a As Double = Val(q(2))
Dim b As Double = Val(q(3))
Dim ab As Double
Try
Select Case q(1)
Case "+"
ab = a + b
Case "-"
ab = a - b
Case "*"
ab = a * b
Case "/"
If b = 0 Then
Return "error"
Else
ab = a / b
End If
Case "sqrt"
ab = Math.Sqrt(a)
Case Else
Return "error"
End Select
Catch ex As Exception
Return "error"
End Try
Dim l As String = Left(prog, begin - 1)
Dim r As String = Right(prog _
, Len(prog) - eind)
prog = l + Str(ab) + r
End While
Return prog
End Function
Public Function mix(pa As String, pb As String) As String
Dim begina As Int16
Dim einda As Int16
Dim beginb As Int16
Dim eindb As Int16
Dim cola As New Collection
Dim colb As New Collection
If Rnd() < 0.5 Then
Dim q As String = pa
pa = pb
pb = q
End If
Dim i As Integer
For i = 1 To Len(pa)
If Mid(pa, i, 1) = "[" Then
cola.Add(i)
End If
Next
For i = 1 To Len(pb)
If Mid(pb, i, 1) = "[" Then
colb.Add(i)
End If
Next
begina = cola.Item(CInt(Rnd() * cola.Count()))
einda = begina
Dim fl As Int16 = 0
While fl > 0
einda += 1
If Mid(pa, einda, 1) = "]" Then fl -= 1
If Mid(pa, einda, 1) = "[" Then fl += 1
End While
beginb = colb.Item(CInt(Rnd() * colb.Count()))
fl = 0
While fl > 0
eindb += 1
If Mid(pb, eindb, 1) = "]" Then fl -= 1
If Mid(pb, eindb, 1) = "[" Then fl += 1
End While
Return Left(pa, begina)
End Function
End Class
Sub Main()
Dim proga As String = "[ + 7 [ - 2 3 ] ]"
Dim progb As String = "[ * 4 [ / 5 6 ] ]"
Dim GP As New GeneProg()
Console.WriteLine("[ test run ]")
Console.WriteLine("prog a = " & proga)
Console.WriteLine("prog b = " & progb)
Console.WriteLine("run a = " & GP.run(proga))
Console.WriteLine("check a = " _
& 7.0 + (2.0 - 3.0))
Console.WriteLine("run b = " & GP.run(progb))
Console.WriteLine("check b =" _
& 4.0 * (5.0 / 6.0))
Console.WriteLine("[ push return ]")
Console.ReadKey()
Console.WriteLine("[ test mix ]")
Dim i As Int16
For i = 0 To 5
Dim c As String = GP.mix(proga, progb)
Console.WriteLine("mix a b = c = " & c)
Console.WriteLine("run c = " & c)
Next
Console.WriteLine("[ push return ]")
Console.ReadKey()
End Sub
End Module
[/code]
error :
run b <> check b
mix frezes my pc
|
|
|
|
|
What you have tried is actually *NOT* a genetic algorithm (GA).
Any genetic algorithm has the following formulation:
0. Generate random values (chromosomes) population;
1. Select a random pair of chromosomes;
2. Recombine chromosomes using cross-over genetic operator;
3. Check if the new child chromosomes are the fittest ones by using objective fitness function;
4. If at least one chromosome in a pair is the fittest, appended it to the array of valid solutions;
4. Mutate those new child chromosomes;
5. Go to step 1 until you've selected N / 2 - chromosomes, where N - the size of population;
6. Proceed with steps 1-5 until you've produced the desired number of fittest solutions;
This is the easies variant of the a classical genetic algorithm.
If you want implement a genetic algorithm, please rework it the way as just I have explained.
And if you've got any questions about how to rework it, just write me in the reply to my post.
|
|
|
|
|
i aready knew that
i wrote some GA's in the past
GP is somthing else
i already have GP/GA working in liberty/just basic
i m just not knowing how to do it in vb2017 jet
i have some detail's wrong
|
|
|
|
|