|
-
Jun 6th, 2000, 02:26 PM
#1
Thread Starter
Junior Member
How do you declare a variable and use a variable which is availabe in any form.
Thankyou
-
Jun 6th, 2000, 03:23 PM
#2
Fanatic Member
Code:
Public MyVar As Integer ' Or Long, Variant, String etc
But it has to be in a Module, not in a form. A public variable in a form is only accessable to that form's functions and subs.
Public Arrays must be declared in modules too.
Paul Dwyer 
Network Engineer
Aussie In Tokyo
Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)
-
Jun 7th, 2000, 04:03 AM
#3
You can also use the Global Keyword.
-
Jun 7th, 2000, 03:00 PM
#4
Frenzied Member
But it has to be in a Module, not in a form. A public variable in a form is only accessable to that form's functions and subs.
Public Arrays must be declared in modules too.
That's not strictly true because public variables in a form are accesable to other parts of the program while the form is loaded
form1:
Code:
Option Explicit
Public intNum As Integer
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Form_Load()
intNum = 5
Form1.intNum = 8
MsgBox Form1.intNum
End Sub
form2:
Code:
Option Explicit
Private Sub Command1_Click()
MsgBox Form1.intNum
End Sub
but yes, public variables would normally go in a module.
Public is ususlly rather than Globalthese days.
Global is a hanger-on from older versions of (Visual) Basic
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|