Qbasicnews.com

Full Version: Global varibles in VB6
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Im quite new to VB and writing a small database thingie. when I open a new form, how do i get the info stored in the varibles on the first form.

example:
I have 2 arrays on Form1

Name(99)
Number(99)
they all have values

I want to put the value of Name(50) into Text1.Text and the value of Number(50) into Text2.Text on Form2

The arrays are Strings if that makes a differance.
I'm assuming you're using VB 6 or earlier - this won't work for VB.NET as written...
If you want true global variables, just put the following in a Module (.BAS):
Code:
Global Name(99) As String
Global Number(99) As String

Or you could just directly reference Form1!Text1.Text (could be written Form1.Text1.Text, but that's less clear!) - just use FormName!ControlName.PropName and it works just like any other control property reference.
Should also mention that you can use
Code:
Public Name(99) As String
Public Number(99) As String
instead of
Code:
Global Name(99) As String
Global Number(99) As String
(Note the use of the Public keyword).

Just thought that'd be handy to know as you will more then likely come across VB code where the programmer has used Public instead of Global.
Thanx guys. Ill try that soon as I get back to my computer.