This is my code for an array textbox . I want to show the addition of array textbox boxpoamount in txttotalamount. but instead of adding each of the value of boxpoamount. the codes only multiply the last textbox of poamount to the number of how many the boxpoamount.
Dim newpoamountbox As New List(Of TextBox)
Private Sub controlall(ByVal controlcount As Integer)
Dim boxpoamount As TextBox
For i As Integer = 1 To controlcount
boxpoamount = New TextBox
boxpoamount.Size = New Drawing.Size(100, 20)
boxpoamount.Location = New Drawing.Point(1013, 542 + 58 * (i - 1))
newpoamountbox.Add(boxpoamount)
Me.Controls.Add(boxpoamount)
Next
Private Sub boxunitpricecom(ByRef boxpoqty As TextBox, ByRef boxpounitprice As TextBox, ByRef boxpoamount As TextBox)
'MessageBox.Show("right")
Dim var1 As String
Dim var2 As String
Dim var3 As String
'Dim var4 As String
'Dim amount As String
Try
var1 = Val(boxpoqty.Text)
var2 = Val(boxpounitprice.Text)
var3 = var1 * var2
boxpoamount.Text = var3
Dim txt As TextBox
Dim Sum As Integer
Dim controlall As Integer = Val(txtpoitemno.Text)
For I = 1 To controlall
txt = CType(Me.Controls(boxpoamount.Text + I.ToString()), TextBox)
Sum = Sum + Double.Parse(boxpoamount.Text)
Next I
txttotalamount.Text = Sum.ToString()
Catch ex As Exception
MsgBox(ex.Message)
Finally
cmd.Dispose()
conn.Close()
End Try
End Sub
boxpoamount.Name = "mytb" + ito help yourself finding the instance of the textboxes later... ah, I see, they are in the list. Then you are good. :)