I am creating multiple textbox with for loop in VB.net, the textbox will show value from array, but when i run it return wrong value, like this:
Y
S
T
E
M
How can i fix it? Here is my script. Thank you.
Dim nameTextbox() As String = {"A", "B", "C", "D", "E"}
For i = 1 To nameTextbox.Length
Dim textbox As New Windows.Forms.TextBox()
textbox.Text = nameTextbox.ToString(i)
textbox.Name = nameTextbox.ToString
textbox.Size = New Size(225, 25)
textbox.Location = New Point(70, 10 25 * (i - 1))
Me.Controls.Add(textbox)
Next
CodePudding user response:
Here is the solution
Dim nameTextbox() As String = {"A", "B", "C", "D", "E"}
For i = 0 To nameTextbox.Length - 1
Dim textbox As New Windows.Forms.TextBox()
textbox.Text = nameTextbox(i)
textbox.Name = nameTextbox.ToString(i)
textbox.Size = New Size(225, 25)
textbox.Location = New Point(70, 10 25 * (i))
Me.Controls.Add(textbox)
Next