Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2007, 03:29 AM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default conditionally selecting buttons

I am relatively new to VB 2005 and have a form with a large number of buttons on it, 256 to be precise they are laid out in 8 rows of 32 and I need to change the colour of them based on a 32 digit binary number I have stored in a string. I will be getting a different binary string for each row of 32 so I thought a way of doing this would be to have a for next loop that goes around 8 times containing another which goes around 32 times. I was going to use mid on the string to find the value and if it was a 1 make the button green and if it is a 0 make it red I could bump the operation to the next line of buttons by adding 32 for the second 64 for the third and so on.

The problem is I can't work out how to select the button to change. I know if it is on the first time round the 8 and say the third time round the 32 then I need to select Button3 to change but I don't know how to code that bit

Can anybody help???

I haven't got much hair left to pull out!

 
Old July 12th, 2007, 06:35 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

If you create 8 sets of the event below for each group of buttons you only have to change the color eight times. For the example below I only added two buttons to the "Handles" info.
    Private Sub Button1_BackColorChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.BackColorChanged, Button2.BackColorChanged
        '* Change the color here
    End Sub




Best Regards,
Earl Francis
 
Old July 12th, 2007, 10:21 PM
Registered User
 
Join Date: Jul 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

unfortunately I have to change individual buttons not blocks of buttons. This will be a graphical display of dynamic information.

 
Old July 13th, 2007, 04:26 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You could make an array with the buttons’ names in it. when you find the button you are after numerically, get the name string out of the array, and use Me(<string here>).BackgroundColor = xxx. (You will, of course need to correct that syntax. Perhaps the syntax is like Me.Controls.Item(<string here>).BackgroundColor = xxx.)





Similar Threads
Thread Thread Starter Forum Replies Last Post
conditionally setting variable ewel Beginning PHP 2 December 13th, 2007 07:39 PM
Conditionally display text mister_mister XSLT 6 March 9th, 2007 11:02 AM
Conditionally display text object leo_vinay Crystal Reports 1 April 18th, 2006 07:22 AM
Prefix zero conditionally: A newbie question soorya Access VBA 2 October 18th, 2004 12:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.