Concat a variable to a control


How can concat a variable to a control, something like this:

Dim var1 as string="1"
Dim button&var1 As New Button

To stay:


best regards
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John Gates, CISSPSecurity ProfessionalCommented:
with the controls collection:

This is accomplished with:

 Dim i As Integer
    i = 1
    Me.Controls("Textbox" & i).Text = "TEST"


Me.controls("lbl" & list(i)).Visible = true

Fernando SotoRetiredCommented:
HI rflorencio;

It is not possible to construct a variable name in that way. What do you need to do to have this requirement?
If it is control, you can use Name property
Dim I  =1
Dim x = New Button With {.Name = "Button" & I}
'Accessing control
Me.Controls("Button1").Text = "Test"

Open in new window

If it's non-control variable, you can use Dictionary
Dim dictVariables As New Dictionary(Of String, YourVarTypeHere)
Dim I  =1
Dim v = New YourVarType
dictVariables.Add("myVar" & i, v)
'Accessing variable

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John Gates, CISSPSecurity ProfessionalCommented:
Did you try what I posted?  Be careful with the statement "It can't be done" I did things with classic ASP that couldn't be done either and made a ton of money doing it :-)

rflorencioAuthor Commented:
It's all i need:

Dim x = New Button With {.Name = "Button" & I}
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.