Results 1 to 18 of 18

Thread: [RESOLVED] limits on variables / labels

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Resolved [RESOLVED] limits on variables / labels

    I keep getting an overflow error when the amount in the variable excceds 32000.

    it is set as dim moneyt as currency

    when the amount gets to 30k i want my calacution to stop adding to it

    my question is

    is there a way to stop the calculation when it reaches 30k?

    thanks

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    Moved from the CodeBank

    How is the calculation being done?

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    money 1 is set as currency as well
    'this is the first part and is the calculation
    If lbl_money = lbl_money.Caption Then
    money1 = toffice * taxoffice
    moneyt = CInt(Label3.Caption + money1)
    End If
    Label3 = moneyt
    ' this produces a msg box and shades the label conserned
    If moneyt >= 30000 Then
    Label3.Enabled = False
    MsgBox ("Stockpile Full")
    End If

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    You might want to try a CLng
    VB Code:
    1. If lbl_money = lbl_money.Caption Then
    2.     money1 = toffice * taxoffice
    3.     moneyt = CLng(Label3.Caption + money1)
    4. End If
    5. Label3 = moneyt
    6. ' this produces a msg box and shades the label conserned
    7. If moneyt >= 30000 Then
    8.     Label3.Enabled = False
    9.     MsgBox ("Stockpile Full")
    10. End If
    An integer is only capable of handling +/- 32K

    Also, how are money1 and moneyt declared?

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    k where abouts would i put it im not to sure

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    wot ever i try with it i keep gettin expected identifer error

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    Quote Originally Posted by KPS.
    k where abouts would i put it im not to sure
    Where would you put what?
    Quote Originally Posted by KPS.
    wot ever i try with it i keep gettin expected identifer error
    Using what code, and on what line of code does the error occur?

    Also, you didn't answer my previous question:

    How are money1 and moneyt declared?

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    sorri i meant to say found the problem and it doesnt have overflow error now thanks for the help
    i just have to get it to stop calculation when it gets to that number now

    (in answer to the question about money1 and moneyt they are delcared as currency)

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    Quote Originally Posted by KPS.
    i just have to get it to stop calculation when it gets to that number now)
    Are you having any difficulties with this?

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    yes i am it just wont stop,

    the whole system is being a pain

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    Lets approach it step by step
    VB Code:
    1. money1 = toffice * taxoffice
    2.     moneyt = CLng(Label3.Caption + money1)
    At the point at which this starts, what does money1 equal, and how does it get to equal whatever that is?

    What is toffice and what does that equal?

    What is taxoffice and what does that equal?

    What is in Label3 and how does it get there?
    Last edited by Hack; Jun 15th, 2006 at 11:40 AM.

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    At the point at which this starts, what does money1 equal, and how does it get to equal whatever that is?

    it is at 0 it works out toffice * the amount a single office brings in which is 100

    What is toffice and what does that equal?

    it holds the amount of tax offices it equals wot ever person puts in (eg 5)

    What is taxoffice and what does that equal?

    the amount 1 office makes it is equal to 100

    What is in Label3 and how does it get there?

    label3 is where the final amount comes out code to display is
    label3 = moneyt

  13. #13
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    Ok...so if money1 reaches 30,000 you do not want it to calculate any more, correct?

    Does the mean the money1 should ALWAYS be 30,000 or Less?

  14. #14

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    yes it should have a cap of 30,000 if that makes more sense

    if it gets to 30k no more should be added to it

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    Quote Originally Posted by KPS.
    yes it should have a cap of 30,000 if that makes more sense

    if it gets to 30k no more should be added to it
    Then add something like
    VB Code:
    1. If money1 > 30000 Then money1 = 30000
    Now, money1 will never have more than 30000 in it.

  16. #16
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: limits on variables / labels

    also, what are you trying to achieve with this line:
    VB Code:
    1. If lbl_money = lbl_money.Caption Then
    That's just going to compare the lbl_money.caption against the default property of lbl_money - which is caption. You're essentially doing:
    VB Code:
    1. If lbl_money.Caption = lbl_money.Caption Then
    which is a bit pointless.

  17. #17

    Thread Starter
    Member
    Join Date
    Jun 2006
    Posts
    35

    Re: limits on variables / labels

    ah rite ill change that

    and the last bit of code worked as well thanks for the help

  18. #18
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: limits on variables / labels

    No problem.

    If you consider this resolved, would you please pull down the Thread Tools menu and click the Mark Thread Resolved menu item? That will let everyone know that you have your answer.

    Thank you.

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