|
-
Jul 8th, 2004, 07:56 AM
#1
Thread Starter
Lively Member
IF statement NOT WORKING! URGENT
Hi Guys
I know this should be simple but it just refuses to work,dont know what I'm missing.
I have this If statement
Code:
IF AmountPaid >= Currentbalance Then
My problem is that when the value for AmountPaid is equal to CurrentBalance the condition returns false,when it should be true.
The values for both variables i'm using is 20 which is double, and the variables are passed ByReference into a sub.
This is driving me crazy,PLEASE HELP,i need to solve this URGENTLY.
THANKS
-
Jul 8th, 2004, 07:59 AM
#2
Fanatic Member
Have you tried:
IF (AmountPaid > Currentbalance) OR (AmountPaid = Currentbalance) Then
?
Do canibals not eat clowns because they taste funny? 
-
Jul 8th, 2004, 08:00 AM
#3
PowerPoster
Have you tried moving them ByValue? Or moving them to variables and using the variables ByValue?
-
Jul 8th, 2004, 08:03 AM
#4
Hyperactive Member
Welcome to the world of floating point arithmetic - where nothing is what it seems.
Your problem stems from the fact that decimal numbers aren't always exactly represented correctly in Doubles (or Singles). There are two ways to correctly check for equality:
1) Test within a very small range.
2) Round to a certain # of decimal places before testing.
An example of #1:
Code:
If Abs(AmountPaid - Currentbalance) < 0.0001 Then
An example of #2:
Code:
If Round(AmountPaid , 2) >= Round(Currentbalance, 2) Then
-
Jul 8th, 2004, 08:09 AM
#5
bpd is completely correct for floating point, but can I just ask why you are using it in the first place?
It seems to me as though the Currency data type (which doesn't have these issues) would be more appropriate.
-
Jul 8th, 2004, 09:44 AM
#6
Fanatic Member
Do other languages have these problems? Or is it just something that is isolated to VB?
-
Jul 8th, 2004, 10:17 AM
#7
Hyperactive Member
Do other languages have these problems?
Yes. I've run across this same issue in FORTRAN - a language designed primarily for numeric computations.
-
Jul 8th, 2004, 11:18 AM
#8
Fanatic Member
Hmm, quite odd, I've never had such a problem as this in VB, but then again I try to limit the use of doubles/singles whenever possible.
-
Jul 8th, 2004, 11:35 AM
#9
Since your working with monetary values, try CCur() >= CCur() first before rewritting all those variables.
-
Aug 7th, 2004, 11:16 AM
#10
Fanatic Member
Seeing that there is a slight chance that I actually wrote the part of the code that calcualtes the cost, interest and capital, in any order, you sould email me that section of the code. and I will fix it.
First off - I am here to help you dude.... I cannot contact you by email because MF monitors the mail server. Wow. Big deal. I have lost your cell number so give me an sms or email me at mikethomson at websurfer.co.za. I am there to steal code either. I only use my own code as a rule, although there are a few really good coders on this forum that I really do trust!!!!
PS: Dont believe what MF said - he was just really disappointed that I left. What sort of a compay do you work for that they will retrnch you rather than offer you better training??? I left because the huge program you are working on is single tier (20000+ lines of sinlge tier code!!!) with no planning and no structure. And the lack of progress on it was starting to make me look like an idiot, and this was not fair because I took over the code from two other developers who had no planning or documentation. I gave my recommendation to modulaizre the code but your managament did not agree with me. Without modularizing the code, and you working on the project, there was actually no room for me to work on it. It was impossible to split tasks. Another thing is that my being there was stinting your development.
Secondly the app should rather have been written in php. This way it could have been easier than VB. I am now fully proficient in writing php applications, and have learnt spans about genuine MySQL security(setting database permissions for users that was not done initially). With my ability you could convert that app into a web based app and offer it locally on your LAN or just as easily load it onto your web server.
After 6 months on my own I have really learnt how to modularize software and by doing this I have finally managed to reduce the time take for each module to about 7 days at run.
Pretty soon I will be in Ladysmith and there are a few other excellant business opportunities there. Greed never drove me before but it is starting to become a factor.
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
|