|
-
Jun 3rd, 2005, 05:10 PM
#1
Thread Starter
New Member
Referring to variable on different form, same project
Hi. I have the below code in a secondary form in a VB game I'm working on (in VB 6.0).
Code:
Private Sub Command3_Click()
If (Command3.Caption = "Continue") Then
beerscore = (Start.scoretotal + drink)
Start.lblScore.Caption = "hello"
Start.scoretotal = Start.scoretotal + drink
MsgBox "Your points have been deposited into your score."
End If
Beergame.Visible = False
Start.Visible = True
End Sub
'scoretotal' is a value on the first form. Am I referring to it correctly in this code? I'm attempting to add the value 'drink' from the current form to 'scoretotal' in the first form, and post that number in 'Start.lblScore' (a lable). The first form is called 'Start'. The one this code is on is called 'beergame'.
I hope that's clear enough, but ask for elaboration and I'll explain further. Thanks in advance for an help.
Last edited by Isolated; Jun 3rd, 2005 at 07:26 PM.
-
Jun 3rd, 2005, 05:17 PM
#2
-
Jun 3rd, 2005, 05:27 PM
#3
Addicted Member
Re: Referring to variable on different form, same project
Hi,
Like Mana said, it looks good to me assuming you have declared ScoreTotal as Public in the form Start like:
'It may be better suited in a module as opposed to a form.
Public ScoreTotal As Long 'whichever data type you are using.
Have a good one!
BK
-
Jun 3rd, 2005, 05:44 PM
#4
Re: Referring to variable on different form, same project
 Originally Posted by Isolated
Hi. I have the below code in a secondary form in a VB game I'm working on (in VB 6.0).
Code:
Private Sub Command3_Click()
If (Command3.Caption = "Continue") Then
beerscore = (Start.scoretotal + drink)
Start.lblScore.Caption = "hello"
Start.scoretotal = Start.scoretotal + drink
MsgBox "Your points have been deposited into your score."
End If
Beergame.Visible = False
Start.Visible = True
End Sub
'scoretotal' is a value on the first form. Am I referring to it correctly in this code? I'm attempting to add the value 'drink' from the current form to 'scoretotal' in the first form, and post that number in 'Start.lblScore' (a lable). The first form is called 'Start'. The one this code is on is called 'beergame'.
I hope that's clear enough, but ask for elaboration and I'll explain further. Thanks in advance for an help. 
Welcome to VB Forums!
You didn't say what problem you were experiencing.
-
Jun 3rd, 2005, 07:25 PM
#5
Thread Starter
New Member
Re: Referring to variable on different form, same project
Ahhh, I had 'scoretotal' as a 'Dim'. Changing it to 'Public' worked, with a couple of small changes. Thanks to everyone who replied!
Yea, by the way, I realized afterward that I hadn't actually asked a question. Heh.
-
Jun 3rd, 2005, 09:44 PM
#6
Junior Member
Re: Referring to variable on different form, same project
It's a matter of scope. Something, no matter how much languages advance, it seems to remain as a basic concept for any language. Isolated, I profusely suggest you to invesitgate on the matter. You could start here. This is one of the things that will take you to the all-time coder's hall of fame.
BluEyes.
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
|