Using variables from one form in another

jgat2011

Member
Joined
Jul 2, 2011
Messages
13
Location
Nairobi-Kenya
Programming Experience
1-3
Hi there,
I would like to pass variables variables from one form to another but the thing is that there is no variable that is actually being passed. Can anyone please help me?
I have tried to use instanciation
Dim f2 as form2
f2=new form2()
f3.textbox1.text="Whatever I want to pass",
but this did not work
 
Thanks to all. I found another alternative and it works.
I used properties. Let me brief you :
I create a module in which I define some properties and use them to store variables from one form by setting the value of the property and using them in another form by using the "get".
e.g. :
VB.NET:
Dim rows as String=""
Public Property [row]() As String
        Get
            Return rows
        End Get
        Set(ByVal value As String)
            rows = value
        End Set
    End Property

Hope it helps ...
 
shorter syntax available. also question: what is []() syntax for?

VB.NET:
    Dim rows as String=""
    Public Property [row]() As String
        Get
            Return rows
        End Get
        Set(ByVal value As String)
            rows = value
        End Set
    End Property

you can just do

Property rows As String


it does the equivalent to what you did. since your doing a basic get,set you do not have to declare the get,set. This is the code it defaults to if you don't specify a get,set
    Private _rows As String
    Property rows As String
        Get
            Return _rows
        End Get
        Set(ByVal value As String)
            _rows = value
        End Set
    End Property

see http://msdn.microsoft.com/en-us/library/dd293589.aspx for more info on it.
 
Last edited:
dim blah as string 'use variable in this form

public blah as string 'use variable in any form

to use the variable in another form -
form2.blah = "whatever"

or

dim test as string = form2.blah
 
Back
Top