Monday, May 24, 2010

How do you use a variable in visual basic so that you can use it on two forms under one solution?

Like a custom input box.

How do you use a variable in visual basic so that you can use it on two forms under one solution?
There are three ways of doing this.





1. On the second form.


Private Var as Object


Public Sub New(Variable as Object)


Var = Variable


End Sub





2. On the first form


Form2.Tag = Variable


Then use the tag on the second Form.





3. Set up another class or module.


Public Variable as Object





In form1


Variable = Var





I suggest using my first sample since that uses Object Orient Standards.
Reply:Been quite a bit of time since the VB days but if my memory serves correctly, you just need to add a "module". Create your variable there using "Public" for the variable type.





ex. Public yourvariable as String


No comments:

Post a Comment