On 2003-10-10, Tor Inge Rislaa <to*************@rislaa.no> wrote:
How to use a public variable
In VB.6.0 I could in the declaration part of a form declare a public
variable, then assign a value to the variable, open a new form and address
the variable and read it's value in my new form.
Form1:
Option Explicit
Public MyVar As String
Private Sub Form_Load()
MyVar = "Some value"
End Sub
Form2:
Private Sub Form_Load()
Dim MyVar2 As String
MyVar2 = Form1.MyVar
End Sub
How is this done in VB.NET
T.I. Rislaa
I'm a little drowsy right now - and was about to stumble up to bed....
So, hopefully what I'm about to say is coherent. If not, well sorry :)
Anyway, what your doing is not possible in VB.NET for the simple fact
that VB.NET does not create default instances of your forms as it did in
VB.CLASSIC. In other words, to access members of one form in another
form, you have to either have an explicit reference (via a constructor
or a property) or you have to create a global reference manually in a
module. The way you do this really depends on the relationship between
forms. Anyway, here is a couple of links that may help you out:
http://www.fawcette.com/vsm/2002_12/...hottips/lobel/ http://www.ftponline.com/Archives/pr...111/qa0111.asp
Anyway, both of these have proposed methods of mimicking the VB.CLASSIC
behavior. Mind you, I haven't made a thorough read of the first
article, just skimed it really - but it looked decent enough... If not
I apologize - but let me know what you think :)
--
Tom Shelton
MVP [Visual Basic]