Results 1 to 11 of 11

Thread: Helped wanted with counter [Resolved, thanks]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194

    Helped wanted with counter [Resolved, thanks]

    As a novice, I have been playing about with this code for ages and still can't get it to do wat I want.

    Could anyone point out to me where I am going wrong?

    What I would like to do is each time the picture moves from the cupboard to the bigcupboard for the cupboardcount to decrement by 1 automatically and bigcupboardcount to increment by1 . The values are shown in labels on forms shown via cmdCupboard and cmdBigCupboard.

    Any help would be appreciated, thanks
    Last edited by mbonfyre; Dec 31st, 2002 at 05:50 AM.

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    what ?
    -= a peet post =-

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    Sorry about that, I meant to post project but was interupted
    Attached Files Attached Files

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Hi again mbonfyre

    I have downloaded the app.
    First of all, ALWAYS use Option Explicit !

    Then you will know when you have misspelled a variable name.
    This is the case in your app.

    Dim bigcupboard As Integer

    should be
    VB Code:
    1. Dim bigcupboardcount As Integer
    -= a peet post =-

  5. #5
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Dim Counter As Integer
    4. Dim Counter2 As Integer
    5. Dim cupboardcount As Integer
    6. Dim bigcupboardcount As Integer
    7.  
    8. Private Sub cmdBigCupboard_Click()
    9.     frmBigCupboard.Show
    10.     frmBigCupboard.lblBigCupboard = bigcupboardcount
    11. End Sub
    12.  
    13. Private Sub cmdCupboard_Click()
    14.     frmCupboard.Show
    15.     frmCupboard.lblCupboard = cupboardcount
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.     Counter = 5000
    20.     Counter2 = 5000
    21.     cupboardcount = 500
    22.     bigcupboardcount = 50
    23. End Sub
    24.  
    25. Private Sub Timer1_Timer()
    26.     Static lLeftPos As Long
    27.     lLeftPos = Picture1.Left + 100 ' move from left postion @ 50 speed
    28.            
    29.     If (lLeftPos + Picture1.Width) > 7000 Then
    30.         lLeftPos = 0 ' when picture1 gets to 3960 it returns to 0
    31.         cupboardcount = cupboardcount - 1 ' decrement store1count by 1
    32.         bigcupboardcount = bigcupboardcount + 1
    33.         frmBigCupboard.lblBigCupboard = bigcupboardcount
    34.         frmCupboard.lblCupboard = cupboardcount
    35.     End If
    36.  
    37.     Picture1.Left = lLeftPos ' position picture1
    38.     If cupboardcount = 0 Then MsgBox ("There are no more toys to go in the big cupboard")
    39.     If bigcupboardcount = 700 Then MsgBox ("The cupboard is full, stuff 'em under the bed!")
    40. End Sub

    I think that is what you are looking for
    -= a peet post =-

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    Dear Peet

    many thanks for your help, Instructing me to use Option Explicit was a good reminder.
    I have so much to learn still, and I couldn't think of a freindlier place to do just that.

    Happy New Year to you

    Sarah

  7. #7
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    did you try the suggested code ?
    -= a peet post =-

  8. #8
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    No sherry there then Peet

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Location
    Propped up at a PC near you...
    Posts
    194
    *New Years resolution - Slow down when answering posts at vbforum

    Yes, the code that you supplied worked perfectly.

    thanks again

  10. #10
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by TheBionicOrange
    No sherry there then Peet
    hehe TBO Sherry is the only sherry I drink
    -= a peet post =-

  11. #11
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    mbonfyre : you should check the "Require Variable Declaration" setting in the option window in vb. This way you don't have to think about adding Option Explicit to all your modules....




    oh, and Happy New Year to you to.
    -= a peet post =-

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