1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

VB 2008 Loop to change a property of many objects

Discussion in 'Software Development' started by brambo, Apr 19, 2010.

Thread Status:
Not open for further replies.
  1. brambo

    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?
     
  2. liquid_vision

    liquid_vision

    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....
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/917933

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice