好的我正在尝试创建批量上传器。用户指定他们拥有的项目数,并创建许多项目和文本框。 Form1获取numberofitems,单击按钮将其存储为表单2可访问的共享变量。默认情况下,Form2加载框,如下所示。我需要做的是将用户输入存储到文本框中,这样我就可以为每个项目创建类。对不起,如果这是复杂的,基本的,烦人的,你有什么。我是vb的新手。
Private Sub ItemInput_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i = 1 To tbnumberofitems
Dim lbl As New Label
lbl.Text = "Label " & CStr(i)
lbl.Name = "lbl" & CStr(i)
lbl.Parent = Me
lbl.Location = New Point(_leftMargin, _topMargin + (i - 1) * _rowHeight)
Dim txt As New TextBox
txt.Name = "txt" & CStr(i)
txt.Parent = Me
txt.Location = New Point(_leftMargin + _labelColumnWidth, _topMargin + (i - 1) * _rowHeight)
Next
End Sub
我的问题是尝试访问这些文本框并将输入存储在一个数组中,我试图在这里做。
Dim itemnamearray(numberofitems) As String
Dim i As Integer = 1 ' loop count''
While i <= tbnumberofitems
Dim lbl As New Label
lbl.Text = "Item " & CStr(i)
lbl.Name = "lbl" & CStr(i)
lbl.Parent = Me
lbl.Location = New Point(_leftMargin, _topMargin + (i - 12) * _rowHeight)
Dim txt As New TextBox
txt.Name = "txt" & CStr(i)
txt.Parent = Me
txt.Location = New Point(_leftMargin + _labelColumnWidth, _topMargin + (i - 1) * _rowHeight)
If i = 1 Then
itemnamearray(0) = txt.Text
Else
itemnamearray(i) = txt.Text
End If
i = i + 1
End While