Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

.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
0
Adam_930
Asked:
Adam_930
  • 4
  • 4
3 Solutions
 
AndyAinscowCommented:
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
0
 
Adam_930Author Commented:
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)
0
 
AndyAinscowCommented:
Trivial, a minor change
        Dim i As Int16, s As String, s2 As String, chk As CheckBox
        i = 2
        s = "CheckBox" + i.ToString
        chk = Me.Controls(s)
        chk.Checked = True

that will set the 2nd checkbox to ticked
Feel free to replace the word "CheckBox"  with whatever you have as the stub of the controls name
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Adam_930Author Commented:
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
0
 
AndyAinscowCommented:
That sounds like the checkbox with the name you supply to me.Controls(...) was not found.  Please check the spelling xxx1 is not the same as Xxx1 for example.
Are these checkboxs on the form or on something else (eg. panel) on the form.  A panel would have its own collection of controls - eg. me.PanelXYZ.Controls(...)
0
 
Adam_930Author Commented:
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???
0
 
AndyAinscowCommented:
Close, you didn't read or understand part of my last comment

For i = 0 To 3
            s = "In" + i.ToString
            chk = Me.GroupBox1.Controls(s)
            chk.Checked = True
        Next
0
 
Adam_930Author Commented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now