Home Can I use a string as a name in Visual Basic to change an objects properties?

# Can I use a string as a name in Visual Basic to change an objects properties?

toblerus
1#
toblerus Published in 2017-11-14 01:36:07Z
 My Idea is not too hard. I have a button, a string called "progname", a TextBox and three Progressbars. When I enter a number into the TextBox and press the button, the following code run's through. Dim progname As String progname = "Progressbar" & TextBox1.Text  Now I have a string called "progname" with relevant value.For an example "Progressbar2". What I want to achieve is write something like: progname.Value += 1  Which can't be done, as "Value" is not a Member of "String". How can I do this? Overall what I want, is to be able to select one of the three progressbars by typing one of the numbers 1-3 into the TextBox and then change that ones porperties.
David Wilson
2#
David Wilson Reply to 2017-11-14 09:37:20Z
 Yes you can. A basic example is this, which searches your form for controls with the name matching your string. It then changes the type to a ProgressBar so you can access all the methods .. Dim progbar As ProgressBar = CType(Me.Controls.Find(progName, False)(0), ProgressBar) progbar.Value += 1 
Promod Piyatissa
3#
Promod Piyatissa Reply to 2017-11-14 02:38:15Z
 Get Prograssbar value into integer type variable. Like Dim progname As String Dim val As Integer val = ProrassBar2.Value  Then increment it val+=1  After that combine it to string progname = val & TextBox1.Text 
 You need to login account before you can post.
Processed in 0.306936 second(s) , Gzip On .