Passing variables between forms

C

Colin

How do you pass variables in one form to another in
VB.NET?

I've looked through MSDN and three books but can't find
how to.
 
H

Herfried K. Wagner [MVP]

* "Colin said:
How do you pass variables in one form to another in
VB.NET?

I've looked through MSDN and three books but can't find
how to.

Add a public property to your 2nd form:

\\\
Private m_UserName As String

Public Property UserName() As String
Get
Return m_UserName
End Get
Set(ByVal Value As String)
m_UserName = Value
End Set
End Property
///

Then set this property:

\\\
Dim f As New FooForm()
f.UserName = "Foo Bar"
f.Show()
///
 
C

Colin

-----Original Message-----


Add a public property to your 2nd form:

\\\
Private m_UserName As String

Public Property UserName() As String
Get
Return m_UserName
End Get
Set(ByVal Value As String)
m_UserName = Value
End Set
End Property
///

Then set this property:

\\\
Dim f As New FooForm()
f.UserName = "Foo Bar"
f.Show()
///

Thanks for your help.

Colin
 
T

Tore Gylver

You can also pass parameters in the forms constructor. If
you search for "constructor" in help index or google you
will find plenty of examples.


Your calling code will be something like this in visual
basic:

Dim FRM as New TestForm (parameter1, parameter2,
parameter3)

Testform.show


Parameter1,Parameter2 and Parameter3 can then be received
in "testform" constructor:

Public Sub New(Byval Parameter1 as int32, byval
Parameter2 as string, Byval Parameter3 as string))


Regards
Tore

gylver thecurl online.no
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top