Results 1 to 6 of 6

Thread: Using an Integer To Store a number

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    28

    Unhappy Using an Integer To Store a number

    Hi, i am just woundering if anyone can help me i am working in VB6.

    i am wanting to store a number like pounds in a integer and then lets say the player wishes to buy somthing like a oven that costs £599 and as 1000 starting money this is the code but its not working does anyone know why.

    General Decorations

    VB Code:
    1. 'Integer that Stores record of the players money
    2. Dim intmoney As Integer

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. 'This sets the players money to 1000 for starting money when the form loads
    4. intmoney = 1000
    5. end sub
    VB Code:
    1. Private Sub oven2_Click()
    2. If intmoney >= 599 Then lockOven2.Visible = False
    3. intmoney = -599
    4. Label4.Caption = "You Bought The New Item"
    5.  
    6.  
    7. If intmoney < 599 Then Label4.Caption = "Sorry But You Can Not Afford This Item"
    8. End Sub


    by the way lockOven2 is a label that is covering and hiding the second oven gaphic so with that not visible you second oven will be.

    sorry if this is a bit of an low level vb question


    thanks in advance
    pipwilky

    Currnet Projects Working on
    Games
    CrossWord (finsihed)
    Programms
    Ip IM

    an more i will up date later


    Please Mark all resloved posts with [RESLOVED] and a green tick.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Using an Integer To Store a number

    Nearly there, try this:
    VB Code:
    1. Private Sub oven2_Click()
    2.  
    3. If intmoney >= 599 Then
    4.    lockOven2.Visible = False
    5.    intmoney = intmoney - 599
    6.    Label4.Caption = "You Bought The New Item"
    7. Else
    8.    Label4.Caption = "Sorry But You Can Not Afford This Item"
    9. End If
    10.  
    11. End Sub

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Using an Integer To Store a number

    Shouldn't it be?
    VB Code:
    1. '...
    2. intmoney = [B]intmoney[/B] - 599
    3. '...

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

    Re: Using an Integer To Store a number

    You didn't say what was not working but I'm guessing that the amount of money in intMoney isn't correct. If so then it looks like this is what you want to do.

    VB Code:
    1. Private Sub oven2_Click()
    2. If intmoney >= 599 Then lockOven2.Visible = False
    3.     [HL="#FFFF80"]intmoney = intmoney - 599[/HL]
    4. Label4.Caption = "You Bought The New Item"
    5.  
    6.  
    7. If intmoney < 599 Then Label4.Caption = "Sorry But You Can Not Afford This Item"
    8. End Sub

  5. #5
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Using an Integer To Store a number

    It should be like this:
    VB Code:
    1. Private Sub oven2_Click()
    2.     If intmoney < 599 Then
    3.         Label4.Caption = "Sorry But You Can Not Afford This Item"
    4.     ElseIf intmoney >= 599 Then
    5.         lockOven2.Visible = False
    6.         intmoney = intmoney - 599
    7.         Label4.Caption = "You Bought The New Item"
    8.     End If
    9. End Sub


    Pradeep

    EDIT: so many posts in one go!
    Last edited by Pradeep1210; Dec 2nd, 2006 at 10:44 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2005
    Posts
    28

    Re: Using an Integer To Store a number

    that you very much for all your replys and kind help.. ill will have go home and try these because my internet's down so i have to go to my mums.....as soon as i have tested theese codes i will post as RESOLVED or not.

    big thanks to :-
    Rob123
    gavio
    MartinLiss
    Pradeep1210

    for all your help, imput and advise.
    regards pipwilky

    Currnet Projects Working on
    Games
    CrossWord (finsihed)
    Programms
    Ip IM

    an more i will up date later


    Please Mark all resloved posts with [RESLOVED] and a green tick.

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