r/visualbasic • u/00jamiil • Apr 04 '19
Variables issue
Hi ppl, i'm not that pro person in VB.
what i'm trying to do is to assign a variable for an item (e.g. Label or Textbox)
a variable looks like their name and the other properties so when i'm in any sub in the code, i can call that variable like: Label1.VarName
i know this is a wrong way but is there any way to such a thing ?
Thanks.
My code:
Dim n As Integer
Private Sub TextBox1(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then Create_new_list_item()
End Sub
Sub Create_new_list_item()
ReDim _labels(n)
_labels(n) = New Label()
With _labels(n)
Dim MyN As Integer = n
.Name = "Label_" + n.ToString
.Text = MyN.ToString
.Width = 100
.Visible = True
.Location = New Point(0, 70 + (n * 24))
AddHandler .DoubleClick, AddressOf Editvalue
End With
Me.Panel1.Controls.Add(_labels(n))
n += 1
End Sub
Sub Editvalue(ByVal sender As Object, ByVal e As EventArgs)
sender.Visible = False
MsgBox(sender.MyN.ToString)
End Sub
1
u/andrewsmd87 Web Specialist Apr 04 '19
Can you go over your use case with me? Like don't worry about the technical aspects, what is the problem you're trying to solve?