[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
Re: limits on variables / labels
Moved from the CodeBank
How is the calculation being done?
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
Re: limits on variables / labels
You might want to try a CLng
VB Code:
If lbl_money = lbl_money.Caption Then
money1 = toffice * taxoffice
moneyt = CLng(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
An integer is only capable of handling +/- 32K
Also, how are money1 and moneyt declared?
Re: limits on variables / labels
k where abouts would i put it im not to sure
Re: limits on variables / labels
wot ever i try with it i keep gettin expected identifer error
Re: limits on variables / labels
Quote:
Originally Posted by KPS.
k where abouts would i put it im not to sure
:confused: 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?
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)
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?
Re: limits on variables / labels
yes i am it just wont stop,
the whole system is being a pain
Re: limits on variables / labels
Lets approach it step by step
VB Code:
money1 = toffice * taxoffice
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?
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
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?
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
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:
If money1 > 30000 Then money1 = 30000
Now, money1 will never have more than 30000 in it.
Re: limits on variables / labels
also, what are you trying to achieve with this line:
VB Code:
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:
If lbl_money.Caption = lbl_money.Caption Then
which is a bit pointless.
Re: limits on variables / labels
ah rite ill change that
and the last bit of code worked as well thanks for the help
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. :)