|
-
May 17th, 2007, 10:25 PM
#1
Thread Starter
Hyperactive Member
Universal Variable?
I know this is a stupid question but I'm really not sure how to do it. I just want to be able to set a variable that can be accessed from any module or form. I know I can just create a form with a textbox that anything can access but is there a way to accomplish the same thing except using a variable instead of a textbox/object? Thank you
-
May 17th, 2007, 10:35 PM
#2
Re: Universal Variable?
Declare the variable as Public in a bas module:
vb Code:
' in Module1
Option Explicit
Public MyVar As Long
From a Form, you can call it like:
vb Code:
MyVar = 1
'or,
Module1.MyVar = 1 'Better. Reduces confusion
-
May 17th, 2007, 10:40 PM
#3
Thread Starter
Hyperactive Member
Re: Universal Variable?
Can I do the same thing if I'm setting the variable in a class module?
-
May 17th, 2007, 10:56 PM
#4
Re: Universal Variable?
 Originally Posted by abazabam
Can I do the same thing if I'm setting the variable in a class module?
You'll have to declare the class as public, ie:
vb Code:
'In a module
Public myClass As Class1
'In a form
Private Sub Form_Load()
Set myClass = New Class1
myClass.Variable = 2
End Sub
'In another form
Private Sub Form_Load()
MsgBox myClass.Variable '2
End Sub
And don't forget to destroy the object before your program closes by using: Set myClass = Nothing
-
May 17th, 2007, 11:05 PM
#5
Re: Universal Variable?
This link will further explain what iPrank and DigiRev have told you.
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
|