Concat a variable to a control

Hi,

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

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

To stay:

button1

best regards
rflorencioAsked:
Who is Participating?

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

x
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:
Yep:
with the controls collection: http://msdn.microsoft.com/en-us/library/7e4daa9c(v=vs.71).aspx

This is accomplished with:

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

Then

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


-D-
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?
ArkCommented:
If it is control, you can use Name property
Dim I  =1
Dim x = New Button With {.Name = "Button" & I}
Me.Controls.Add(x)
'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
dictVariables("myVar1").SomeProperty=xxx

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 :-)

-D-
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.