areyn Posted September 4, 2003 Posted September 4, 2003 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. Quote
*Experts* mutant Posted September 4, 2003 *Experts* Posted September 4, 2003 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. :) Quote
areyn Posted September 4, 2003 Author Posted September 4, 2003 i don't mean to sound naive but how do I edit the constructor. could you briefly show me a code example. i appreciate your helping. Quote
*Experts* mutant Posted September 4, 2003 *Experts* Posted September 4, 2003 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) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.