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
2
u/00jamiil Apr 04 '19
I did a runtime creation for Label and Textbox when ever i pressed enter and both of them are laying above each other, anyway i want whenever i double clicked the label to hide it and show the textbox then when i press enter in the textbox the label will show again and the textbox will be hidden.
remember that these items created while the program is running and everyone of them is assigned to a value in an array.
i hope u understand me XD