VB 2008 Loop to change a property of many objects

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

brambo

Thread Starter
Joined
Apr 19, 2010
Messages
1
I am writing a "Bingo Card" program for a class. My question is way ahead of the syllabus.

I have 25 buttons named btn_1, btn_2, and so on to btn_25.
I would like to use a FOR Loop to set the backcolor of each button to white. I think this should be take about 4-6 lines. I am currently using 25 lines of code to do this.

My problem is that I cannot program the loop to cycle through the 25 buttons. I keep getting a syntax error at btn_. In FORTRAN I would (if i remember right) append the index variable to "btn_". This does not work. Maybe I need to convert the integer index to another data type, but I obviously don't know enough at this point.

Any suggestions?
 
Joined
Apr 17, 2010
Messages
41
Not being familiar with the syntax of VB 2008, I cannot give you a code example.

However, in previous versions of VB .NET, the way object properties are handled is the same as in java.

I believe that to adjust all of the buttons, you would have to first get the parent container of the buttons, and read the list of objects on it into an array.

Once you have the, create a loop which will pick up each object in turn, and check its type.

If it is a button, create a new button object, and cast the object you are adjusting into the new button.

Changing the property of the new named object *should* effect the object you have just cast from,however, this is a long winded method,and I honestly can't say if it will work at all....
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Members online

Top