The following code creates textboxes on a form according to the contents of an array named ProdName.
The array; along with "intCount"; is declared in another form named WNew as "Public Shared".
intCount is used to count the number of products entered in WNew and is therefore used to tell this form how many textboxes to create in the loop.
The "tbName" textboxes contain the information drawn from the ProdName array in WNew - and (miraculously) this works!
Where I'm going with this is that when the blank textboxes "tbCrates" are produced alongside the "tbName" boxes the user enters a figure in these boxes. Ideally I need that entered figure stored in an array; but everything I've tried so far fails because I'm struggling to access coded textboxes.
In an Ideal world, if ProdName(1) is, let's say, "Bike" and the user types in 15, then a "Quantity" array should show 15 in Quantity(1).
Does anyone have a solution? I should stress that this is not for commercial purposes but is purely something I'm working on for myself for personal use and to help me learn how to program.
Expand|Select|Wrap|Line Numbers
- Public Shared tb(100) As TextBox
- Dim Crates(100) As String
- Dim n As Integer = 1
- Dim r As Integer = 176
- Dim t As Integer = 1
- Private Sub WPurchases_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- If WNew.ProdName(1) <> "" Then
- For i = 1 To WNew.intCount
- tb(n) = New TextBox
- tb(n).Name = "tbName" & n.ToString
- tb(n).Text = WNew.ProdName(n)
- tb(n).Size = New Size(148, 20)
- tb(n).Location = New Point(21, r)
- tb(n).BorderStyle = BorderStyle.Fixed3D
- Me.Controls.Add(tb(n))
- tb(t) = New TextBox
- tb(t).Name = "tbCrates" & n.ToString
- tb(t).Size = New Size(55, 20)
- tb(t).Location = New Point(175, r)
- tb(t).BorderStyle = BorderStyle.Fixed3D
- Me.Controls.Add(tb(t))
- n += 1
- t += 1
- r += 24
- Next i
- End If
- End Sub