trying to control an array of button colors

cncmachineguy

Member
Joined
Aug 3, 2013
Messages
8
Programming Experience
10+
I have done some searching for this both here and google. As you can imagine using array and control or button gets LOTS of hits. So if I am re-hashing an already answered question please be kind.

I am trying to create a GUI as a front end to an I/O card I have built. It enumerates over USB as a HID device. All works fine there. What I have so far is 2 groups of 14 buttons that represent pins on my board. My firmware sends back the state of all pins and VB parses to decide on what color a button should be. I like using the buttons as they work well as dual purpose in my app. I can set a pin or read it using just the button.

Here is where I need help-

I have an array called PinColor() as Color.
Once I have all the colors set, I then have 28 lines of code:
VB.NET:
button1.backcolor = pincolor(0)

now it occurs to me there must be a better way to assign the color value to each button. I can live with it for 28 pins, but I have 85 total and just can't imagine there is not a better way.

this is what I would like to do but assume it won't work since I can't name the buttons with an index (at least I don't know how):
VB.NET:
dim i as integer
for i = 0 to 27
     button(i).BackColor = PinColor(i)
next
 
well that is really good to know. Ultimately I would like to have sets of buttons, labeled RA0-RA15, RB0-RB15, and so forth. If I can get their names as Herman suggests, and keep them in seperate arrays, that would be really nice. If not I can deal with 1 array as long as I can keep straight who is where. And Thank you solitaire for further explanation on z-reordering.
Or you could just put them in arrays yourself.
 
Being new to this, I thought that was what I was doing here?

What I mean is that, rather than relying on the names of the controls at all, just put the ones you want into the arrays you want and then access them by index, e.g.
Private arr1 As Button()
Private arr2 As Button()

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    arr1 = {Button1, Button2, Button4}
    arr2 = {Button3, Button5, Button6}
End Sub
I'm not saying that you should change the names but, if you create the arrays this way, the names don't matter at all
 
Back
Top