Filling label on form 2 with textbox from form 1

Nopelken

New member
Joined
Nov 11, 2014
Messages
1
Programming Experience
1-3
I want to fill some labels on form 2 with the text from textboxes from form1
I tried:

Dim maxvalue As Integer = 16
Dim frm As New Form2
For i As Integer = 1 To maxvalue
Dim txt() = Me.Controls.Find("TextBox" & i, True)
Dim lbl() = frm.Controls.Find("Label" & i, True)
lbl(i
).Text = txt(i).Text
Next frm.Show()

But I get an index out of range

and:
Dim maxvalue As Integer = 16
For i As Integer = 1 To maxvalue - 1
CType(Me.Controls("Label" + i.ToString), Label).Text =
Form1.(ctype(Me.Controls("textbox" + i.ToString), TextBox.Text)
Next

Error on Ctype

Anyone can help ?

 
Firstly, please post code snippets one way and one way only, i.e. as plain text in formatting tags, e.g.

[xcode=vb]your code here[/xcode]

That will provide syntax highlighting and, most importantly, retain indenting.

With regards to the first issue, think about what your index values are. You're using `i` as the index and it has values ranging from 1 to 16. Are the arrays returned by Find ever going to have an element at index 16? Are they ever going to have an element at index 1? How many elements do you expect those arrays to have? What does that say about what indexes are valid?

As for the second issue, if there's an error then there's an error message. Any reason you chose not to share that with us?
 
Back
Top