English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a string A = "textbox23"
I have an integer X that I want to output


how do I get my program to execute:

textbox23.Text = X

using the info from the string?

2007-03-09 04:30:38 · 3 answers · asked by cpine505 3 in Computers & Internet Programming & Design

I thought of doing what you did below, with IF statements, but what if I have hundreds of text boxes thatcould be outputed to, I don't want to write hundreds of IF statements...I was hoping to create some kind of loop.

2007-03-09 04:48:05 · update #1

3 answers

I may be reading this wrong, but are you saying that your variable, A, contains the name of the text box that you want to print X out to?

If so, the only way that I have ever done this is to use an if statement, and determine what A is, and then use an explicit assign in the then:

if A = "textbox23" then
textbox23.text = cstr(x)
elseif A = "textbox24" then
textbox24.text = cstr(x)
end if

2007-03-09 04:39:23 · answer #1 · answered by dmc177 4 · 0 0

Dim A as string = "textBox23"
Dim X As Integer = 123
Me.Controls(A).Text = X.ToString()

This takes the control with the name of "textBox23" and assigns it's text property the value of the integer "X."

If you have lots of controls on the form, as long as you have their names you can use the name in a variable by using the Me.Controls(varName) as above. Otherwise you would have to hard-code everything, which you obviously do NOT want to do.

2007-03-09 13:08:09 · answer #2 · answered by Gene 3 · 0 0

Dim A As String = "textbox23"
TextBox23.Text = A


you can't cast a string to an integer you can cast a integer to a string integer is for numbers

2007-03-09 13:03:17 · answer #3 · answered by groundbrandon 3 · 0 0

fedest.com, questions and answers