Link to home
Start Free TrialLog in
Avatar of Adam_930
Adam_930

asked on

.NET Control Arrays

I am just not getting it..... I am not sure what/how to ask differently, but I don't understand what my options are.

I have a piece of manufacturing equipment that was written and controlled in a VB6 application. This is now being converted to a VB.NET application. (VB 2013)
One form has 112 checkboxes that were used to display the status of real world discrete input & outputs to the machine. this was accomplished in VB6 through the use of checkboxes in a an array.
One group of the checkboxes, the inputs, were called In(0) through In In(79). The other group, the outputs, were called Out(80) through Out(111) for a total of 112.
The checked status let the operator know if the device was ON or OFF. Checked ==> ON, UNCHECKED ==> OFF.
This was accomplished through a loop
bDSig(xx) is a boolean variable that corresponds to the status of the real world input.

VB6 code

For IOLoop = 0 To 79
    If bDSig(IOLoop) = True Then
        frmIO.In(IOLoop).Value = 1
    Else
        frmIO.In(IOLoop).Value = 0
    End If
Next IOLoop

For IOLoop = 80 To 111
    If bDSig(IOLoop) = True Then
        frmIO.Out(IOLoop).Value = 1
    Else
        frmIO.Out(IOLoop).Value = 0
    End If
Next IOLoop

When I wizarded the original VB6 application it renamed the checkboxes _In_0, _In_1, _In_2, _Out_80, _Out_81, etc
I have gone through and renamed all the checkboxes In0, In1, In2, In3, Out80,, Out81, Out82, etc.
Is there now a way to loop these items to update them?
I need a very specific response on the way to do this in .NET world, I've tried asking this before and I am still struggling, and I'm not sure what I am missing. I have a lot of screens with a lot of information that I use to be able to just loop through to update, I am trying to understand the proper way to approach this.  I don't need a link, I need an example
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Dim i As Int16, s As String, s2 As String, chk As CheckBox
        For i = 1 To 3
            s = "CheckBox" + i.ToString
            chk = Me.Controls(s)

            s2 = s2 + s + " is " + chk.Checked.ToString + ","
        Next
        MessageBox.Show(s2)
the above will show you the state of 3 checkboxs - more or less what you want
Avatar of Adam_930
Adam_930

ASKER

Andy,
I am trying to assign the value of the many checkboxes,
I am trying to assign the checkbox.checked as either ON or OFF based on status of the input / outputs.

Example:I      In0.checked = bDSig(0)
SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Andy, I am starting to see what you are doing, but I am getting the error

A first chance exception of type 'System.NullReferenceException' occurred in frmIO.exe

when I get to line:     chk.Checked = True
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is what I currently have in my code:
My checkboxes are currently inside a GroupBox

        For i = 0 To 3
            s = "GroupBox1.In" + i.ToString
            chk = Me.Controls(s)
            chk.Checked = True
        Next

I used the copy & paste from the (Name) to make sure I didn't have a typo
I have tried with with and without the GroupBox1,
I have tried by adding Me.GroupBox1

I just tried moving my checkboxes to outside of my GroupBox and used the following

        For i = 0 To 3
            s = "In" + i.ToString
            chk = Me.Controls(s)
            chk.Checked = True
        Next

This worked, what am I missing inside the GroupBox???
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THANK YOU VERY MUCH,
I have been struggling with this much longer than I want to admit.
I hope others can find your solution before they go through the pains I went through.