Dear All,

From the below codes, I can get the values of text boxes x1,x2 in the Textbox1 of form2. (when I write x1 or x2 in the textbox 2 of form2.)
But when I write c1 or c2 in the Textbox1 of form2 then it gives error.

Pl. help me.
(I know that the function used in form 2 returns only value of a textbox, not a variable. Pl. tell me the right function that can return the value of a variable.)

Thanks & Regards
Himanshu Verma

My codes have been shown below:

'In form 1

Public Class Form1
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
x1.Text = 1
x2.Text = 2
c1 = 10
c2 = 20

End Sub
End Class

'In form 2

Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = Form1.Controls(TextBox2.Text).Text
End Sub
End Class


Module Module1
Public c1, c2 As  Integer

End Module

c1 and c2 are variable not controls. You can't look up their names in the control collection. I would suggest you research using Reflection.

commented: ..Actually I am new to the I don't know how to use "reflection" in this programm. Can you please. give me an example to solve my problem. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.