Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
hi i have a simple vb.net question. how do i pass a variable from a class in one form to a class in a different form OR, how do i declare the variable so that it is already recognized in both forms. thanks.
  • *Experts*
Posted

If you want to pass it between forms then you could edit the constructor to accept that variable of the form that you pass the variable into. If you want a variable that is accessible to all forms and classes then simply create a class that will hold a shared instance of the variable.

:)

  • *Experts*
Posted

Your form right now should have something like this:

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Thats the constructor. You have to change it so it accepts an argument:

Dim anobject As argtype 'variable that will store what you passed in
Public Sub New(ByVal arg As argtype) 'accept an argument
MyBase.New()
InitializeComponent()
anobject = arg 'assign the passed in object to the local variable

Then when you declare your form:

Dim NewForm As New Form2(the object you pass in)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...