|
-
Oct 2nd, 2000, 09:50 PM
#1
Thread Starter
New Member
I am making a little program that requires a variable from one form to end up on another. I use that Public statement but when I compile or run the program, I get an erro message saying the variable is not defined. any inference into what the problem is would be greatly appreciated.
Thank You Much
Pie, I'm just going to go like this and if you get eaten, it's your own fault.- Homer Simpson
-
Oct 2nd, 2000, 09:55 PM
#2
what kind of variable is it, because some kinds can't be declared as Public variables
-
Oct 2nd, 2000, 09:55 PM
#3
Fanatic Member
If you need the variable from one form to appear on the other, you need to access the object followed by the variable.
For instance
Form1:
Public Happy As String
Form2:
Dim MyNews
Private Sub Form_Load()
MyNews = Form1.Happy
Msgbox MyNews
End Sub
Hope this helps
-
Oct 2nd, 2000, 10:01 PM
#4
Fanatic Member
Actually, let me put up some working code so you get a better idea.
Form1 (put a command button on form1):
Code:
Public Happy As String
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Form_Load()
Happy = "Happy"
End Sub
Form2:
Code:
Private Sub Form_Load()
MsgBox Form1.Happy
End Sub
Hope that will clear things up. There are some things which cannot be declared public on a form, but at the moment, I'm reletively unsure what they are. The above example does, however, work 
-
Oct 2nd, 2000, 10:04 PM
#5
Dim it.
Code:
INTEGER
Dim myINT As Integer
Private Sub Form_Load()
myINT = 0
End Sub
Private Sub Command1_Click()
myINT = myINT + 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Msgbox myINT
End Sub
Code:
STRING
Dim myString As String
Private Sub Form_Load()
myString = "Hello"
Msgbox myString
myString = "Good bye"
End Sub
Private Sub Form_Unload(Cancel As Integer)
Msgbox myString
End Sub
You should also remove Option Explicit, it's not needed.
Pretty easy to understand .
-
Oct 2nd, 2000, 10:39 PM
#6
Fanatic Member
I may be wrong, but using dim won't allow another form to grab the information from that variable, will it?
>I am making a little program that requires a variable from
>one form to end up on another.
That requires the use of Public and accessing that variable through:
object.XXX (XXX can be an object, variable, sub, function, control, or property as long as
it's been declared as public.)
I could be wrong about the Dim statement, but I do know that I was able to access the variable from one form on another using public and the above syntax.
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
|