Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > How to use variable variable name?
 

How to use variable variable name?

I have 100 textbox in my form. Their names are tb1, tb2, ... tb100

I need to retrieve the values from these 100 textboxes.

How can I use a loop to address these 100 textboxes name?

Zod  Saturday, September 02, 2006 1:04 PM
Try this:
Dim values(99) As String
For ix As Integer = 1 To 100
Dim txt As TextBox = Me.Controls("tb" + CStr(ix))
If txt IsNot Nothing Then values(ix-1) = txt.Text
Next

nobugz  Saturday, September 02, 2006 2:31 PM

for each currentControl as Control in Me.Controls

if TypeOf(currentControl) Is TextBox then

Dim theTextBox as TextBox = currentControl

'do your stuff with theTextBox as it has now been made the same textbox as the textbox on the control

end if

next

ahmedilyas  Saturday, September 02, 2006 1:37 PM
Try this:
Dim values(99) As String
For ix As Integer = 1 To 100
Dim txt As TextBox = Me.Controls("tb" + CStr(ix))
If txt IsNot Nothing Then values(ix-1) = txt.Text
Next

nobugz  Saturday, September 02, 2006 2:31 PM

You can use google to search for other answers

Custom Search

More Threads

• Message pump and console app
• Strange MS OLEDB Provider problem
• Connecting a OPC-Server in VB.Net
• saving
• How to save infomation in a .dat file?
• Help with coding a confirm message
• Problem with VB.NET 2005 accessing Active Directory attribute "managedObjects"
• Package & Deployment Error
• Change cursor in Drag Drop
• WithEvents' variable does not raise any instance events that are accessible - Code Snippet Posted