VB.NET and Control Arrays
Posted on 2014-04-17
I realize that with VB.NET that control arrays are no longer used. However, I have an application written in VB version 6 that has 17 instances (0 to 16) that do use control arrays. One of the buttons in the control array has an effect on two text boxes and since I can use control arrays, the code for this is as follows:
Private Sub btnSetOut1_Click(Index As Integer)
Dim i As Integer
i = Index
'validate manual setting
If Not IsNumeric(txtOut1(i).Text) Then
MsgBox "Invalid Entry: Only numeric values are allowed", vbOKOnly + vbExclamation, "Invalid Data Entry"
ElseIf Val(txtOut1(i).Text) < 0 Or Val(txtOut1(i).Text) > 100 Then
MsgBox "Invalid Entry: The output must be in the range of 0 and 100", vbOKOnly + vbExclamation, "Invalid Data Entry"
If UCase(CtrlOutputType$(i%)) = "SINGLE" Then
UT550OutputValWrite% CtrlChan(i), Val(txtOut1(i).Text)
ElseIf UCase(CtrlOutputType$(i%)) = "DUAL" Then
'if DUAL set txtOut2 to 0.0
If Val(txtOut1(i).Text) > 0 Then
txtOut2(i).Text = "0.0"
UT550WriteHOutputValue% CtrlChan(i), Val(txtOut1(i).Text)
UT550WriteCOutputValue% CtrlChan(i), Val(txtOut2(i).Text)
Now, this is ALL the code I need to handle all 17 instances the 'btnSetOut1'. I believe that if I were to attempt to write this program in VB.NET, I would need to replicate the above code 16 more times!
That seems extremely tedious so I am wondering if someone can explain to me an easy way to do the same thing in VB.NET that I did in the VB6 code above.
I would think that the programming would be easier, not more difficult.
Thanks in advance,