Hello. I am fairly new to VisualBasic .NET (2008). I'm creating an application that, when a number is entered into the textbox, a new form window is created and populated with buttons.
Each button starts the same command, but with a different parameter (the parameter being the pertinent record number found by the search).'
The records are asset tag numbers.
The procedure works fine if there is only one result.
But the search allows for partial numbers and that's where the trouble begins.
If two or more results are found, each button is configured with the last number found. The button being clicked doesn't tally with the proper ID number. (Note: Each button made displays the record number found. )
Here's the code and I'll explain other aspects of it:
In the DynamicClick sub, the "sender" variable is a button type and cannot be converted to string. Hence this value being altered to read the value in Form3_text.
What I didn't count on was that the event is only called when a button is clicked. When buttons are made, they are not assigned at that time.
I've had problems trying to carry over the (current value) for pcArray(i), hence having it populate that form3_text field. When trying to add in a second object to be passed, I get the following error:
"Method prtivate sub DynamicClick(sender as object, pcNameInfo as object, e as system.eventargs) does not have a signature compatible with delegate sub event handler with delegate 'delegate sub eventhandler(sender as object e as system.eventargs)."
I tried manually entering a "Delegate sub eventhander" with the pcNameInfo object and VB 2008 ignores it.
What can I do to get each newly made button to be told to run the RemoteIn(pcArray(i)) process properly?
Thank you much!!
Each button starts the same command, but with a different parameter (the parameter being the pertinent record number found by the search).'
The records are asset tag numbers.
The procedure works fine if there is only one result.
But the search allows for partial numbers and that's where the trouble begins.
If two or more results are found, each button is configured with the last number found. The button being clicked doesn't tally with the proper ID number. (Note: Each button made displays the record number found. )
Here's the code and I'll explain other aspects of it:
VB.NET:
For Each Line In File.ReadAllLines(fileSpecX)
Dim pcArray As String() = Line.Split(New Char() {","c}) 'strips ALL after the first value's comma - in this case all domain info after the computer name - one dimensional array
j = pcArray(i).Length
Dim btn(i) As Button
pcArray(i) = pcArray(i).Substring(4, (j - 4)) ' truncates "CN=
' removing textbox and dropdown
' Form3_PC_buttons.foundPcComboBox.Items.Add(pcArray(i))
' fullScreen = fullScreen + pcArray(i) + Environment.NewLine ' populates display for textbox
' Form3_PC_buttons.btn(i) = New Button
btn(i) = New Button
btn(i).Location = New Point(k, l)
btn(i).ForeColor = White
btn(i).BackgroundImage = My.Resources.blue
btn(i).SetBounds(k, l, 80, 20)
btn(i).Text = pcArray(i)
Form3_PC_buttons.Controls.Add(btn(i))
' fill "dummy" value to be carried over, as delegation currently works only with one variable being crossed over.
'Two created a mismatch and, so far, has not been able to be fixed.
Form3_PC_buttons.placeHolder_Form3.Text = pcArray(i)
AddHandler btn(i).Click, AddressOf DynamicClick
i += i
' k += 1
l += 25
tcount += 1
mcount += 1
If mcount = 3 Then
k += 90
l = 10
mcount = 0
End If
Next
VB.NET:
Private Sub DynamicClick(ByVal sender As System.Object, ByVal pcNameInfo As System.Object, ByVal e As System.EventArgs)
sender = Form3_PC_buttons.placeHolder_Form3.Text ' replace piped data with the name of the PC, placed in the hidden field, we want to remote in to.
RemoteIn(pcNameInfo)
End Sub
In the DynamicClick sub, the "sender" variable is a button type and cannot be converted to string. Hence this value being altered to read the value in Form3_text.
What I didn't count on was that the event is only called when a button is clicked. When buttons are made, they are not assigned at that time.
I've had problems trying to carry over the (current value) for pcArray(i), hence having it populate that form3_text field. When trying to add in a second object to be passed, I get the following error:
"Method prtivate sub DynamicClick(sender as object, pcNameInfo as object, e as system.eventargs) does not have a signature compatible with delegate sub event handler with delegate 'delegate sub eventhandler(sender as object e as system.eventargs)."
I tried manually entering a "Delegate sub eventhander" with the pcNameInfo object and VB 2008 ignores it.
What can I do to get each newly made button to be told to run the RemoteIn(pcArray(i)) process properly?
Thank you much!!