Results 1 to 6 of 6

Thread: Referring to variable on different form, same project

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Resolved 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.

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Referring to variable on different form, same project

    If Start is the name of the other form, then it looks right. Have you tested it? Do any errors occur?


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Addicted Member
    Join Date
    May 2005
    Posts
    168

    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

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Referring to variable on different form, same project

    Quote 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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Resolved 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.

  6. #6
    Junior Member BluEyes's Avatar
    Join Date
    May 2005
    Location
    B.A. - Argentina
    Posts
    21

    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
  •  



Click Here to Expand Forum to Full Width