473,473 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically changing button label from a variable

Hello,

I have an arraylist that looks like this: 1,4,6

I have buttons called button1, button4, button6.

I would like to change the text on the buttons that corispond to the
numbers in the array. Is there a dynamic way to do this? or do I have
to loop through the arraylist and use a switch to update them?

like is ther any way to do something like this

Dim button as String
For i = 0 To al.Count - 1
button = "button" & al.Item(i)
button.Text = "text changed"
Next

thanks!

Nov 4 '06 #1
3 2220
Paulers,

In VB2005 you could do something like this:

For Each i As Integer In al
Me.Controls("Button" & i.ToString).Text = "Text changed"
Next

Kerry Moorman
"Paulers" wrote:
Hello,

I have an arraylist that looks like this: 1,4,6

I have buttons called button1, button4, button6.

I would like to change the text on the buttons that corispond to the
numbers in the array. Is there a dynamic way to do this? or do I have
to loop through the arraylist and use a switch to update them?

like is ther any way to do something like this

Dim button as String
For i = 0 To al.Count - 1
button = "button" & al.Item(i)
button.Text = "text changed"
Next

thanks!

Nov 4 '06 #2
If you control over how it is all set up (i.e. you've created the array and
the buttons) perhaps it would be better to create an array of buttons
references. It is quite limiting to enforce a rule whereby buttons must be
named "button1", etc. in order for a routine to work. If instead you create
an array of button references "any" button can be included and (in your
example) the button text will change.

Consider not hard coding the "text" into your loop as well. You can pass
the text into the method along with the array and FOR EACH the text into
every button in the array and then any number of buttons can be changed to
any arbitrary chunk of text.

Tom
"Paulers" <Su*******@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello,

I have an arraylist that looks like this: 1,4,6

I have buttons called button1, button4, button6.

I would like to change the text on the buttons that corispond to the
numbers in the array. Is there a dynamic way to do this? or do I have
to loop through the arraylist and use a switch to update them?

like is ther any way to do something like this

Dim button as String
For i = 0 To al.Count - 1
button = "button" & al.Item(i)
button.Text = "text changed"
Next

thanks!

Nov 4 '06 #3
Paulers,

In addition to the others, the Tag property can be very handy in this to
seperate some buttons from others.

Otherwise of course the array of existing buttons

dim myButtonArray as button() = {button1, button4, button6, buttonwhatever}

Cor

"Paulers" <Su*******@gmail.comschreef in bericht
news:11**********************@b28g2000cwb.googlegr oups.com...
Hello,

I have an arraylist that looks like this: 1,4,6

I have buttons called button1, button4, button6.

I would like to change the text on the buttons that corispond to the
numbers in the array. Is there a dynamic way to do this? or do I have
to loop through the arraylist and use a switch to update them?

like is ther any way to do something like this

Dim button as String
For i = 0 To al.Count - 1
button = "button" & al.Item(i)
button.Text = "text changed"
Next

thanks!

Nov 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeffrey Barish | last post by:
Is there a way to fill the values in an OptionMenu dynamically? I need something like the add_command method from Menu. Is there a better way to implement a pull-down list? -- Jeffrey Barish
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
6
by: Test Message | last post by:
I need to dynamically add an html control to a web form. What I have, thus far, adds the control to the page, but only places it after the closing "</html>" tag. ...
3
by: Bijoy Naick | last post by:
I have something strange going on.. My .aspx page contains a file upload control, a "Import Data" button, a "newTransactions" <asp:table>, a"SaveTrans" button and an confMsg label. First the...
2
by: jmarendo | last post by:
Hello, After reading through the "Table Basics - DOM - Refer to table cells" example at mredkj.com , I modified the code for my own purposes. In the modified version, I create a hyperlink and...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
3
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.