|
-
Jun 15th, 2006, 10:23 AM
#1
Thread Starter
Member
[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
-
Jun 15th, 2006, 10:25 AM
#2
Re: limits on variables / labels
Moved from the CodeBank
How is the calculation being done?
-
Jun 15th, 2006, 10:33 AM
#3
Thread Starter
Member
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
-
Jun 15th, 2006, 10:36 AM
#4
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?
-
Jun 15th, 2006, 10:38 AM
#5
Thread Starter
Member
Re: limits on variables / labels
k where abouts would i put it im not to sure
-
Jun 15th, 2006, 10:50 AM
#6
Thread Starter
Member
Re: limits on variables / labels
wot ever i try with it i keep gettin expected identifer error
-
Jun 15th, 2006, 10:53 AM
#7
Re: limits on variables / labels
 Originally Posted by KPS.
k where abouts would i put it im not to sure
Where would you put what?
 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?
-
Jun 15th, 2006, 11:00 AM
#8
Thread Starter
Member
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)
-
Jun 15th, 2006, 11:16 AM
#9
Re: limits on variables / labels
 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?
-
Jun 15th, 2006, 11:20 AM
#10
Thread Starter
Member
Re: limits on variables / labels
yes i am it just wont stop,
the whole system is being a pain
-
Jun 15th, 2006, 11:23 AM
#11
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?
Last edited by Hack; Jun 15th, 2006 at 11:40 AM.
-
Jun 15th, 2006, 11:33 AM
#12
Thread Starter
Member
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
-
Jun 15th, 2006, 11:41 AM
#13
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?
-
Jun 15th, 2006, 11:43 AM
#14
Thread Starter
Member
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
-
Jun 15th, 2006, 11:46 AM
#15
Re: limits on variables / labels
 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.
-
Jun 15th, 2006, 11:53 AM
#16
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.
-
Jun 15th, 2006, 12:02 PM
#17
Thread Starter
Member
Re: limits on variables / labels
ah rite ill change that
and the last bit of code worked as well thanks for the help
-
Jun 15th, 2006, 12:17 PM
#18
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|