| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

07-21-06, 02:37
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 103
|
|
|
problem on double variable
|
|
I have a problem on Double variable
eg.
dim d as double
'while a, b, c is value from cell A1, A2, A3, eg. A1=1.5, A2=3.35 , A3=3.65
d = a+b+c
'now, when i compare the value
if d<8.5 then
Msgbox "d is less than 8.5"
end if
'the weird thing happen was, when d=8.5, it will go in to print out 'd is less than 8.5'
but if i set d=8.5, not d=a+b+c, then it won't print that message, because d is not less than 8.5
can anyone tell me why this is happening?
|
|

07-21-06, 08:11
|
|
Registered User
|
|
Join Date: Apr 2004
Location: Derbyshire, UK
Posts: 714
|
|
Hi
Not sure what the problem is, but I get no message from either of these
Code:
Sub test1()
Dim a As Double
Dim b As Double
Dim c As Double
Dim d As Double
a = Range("A1") '= 1.5
b = Range("B1") '= 3.65
c = Range("C1") '= 3.35
d = a + b + c
If d < 8.5 Then MsgBox "d is less than 8.5"
End Sub
Sub test2()
Dim d As Double
d = Range("A1") + Range("B1") + Range("C1")
If d < 8.5 Then MsgBox "d is less than 8.5"
End Sub
???
MTB
|
|

07-23-06, 22:15
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 103
|
|
|
|
Thats what i think too, actually the program was written by previous programmer, however, only recently we found out this is happening, i tried to look into the problem, and found out that, the program tried to add a few double value a+b+c, then when i debug i can see the value is equal to 8.5
then it went in a if statement
if a+b+c < 8.5 then
'inform the user they has entered a value less than 8.5
but even a+b+c = 8.5 the computer still prompt the message, hm..i currently do not have time to remove some of the sensitive data and post the template here. (this is a timesheet input for all our company's staff, and probably i need time to remove those that need to remove b4 posting the template here)
Thanks.
|
|

07-23-06, 22:15
|
|
Registered User
|
|
Join Date: Jun 2006
Posts: 103
|
|
oh...sorry, i posted twice for the same message, i removed the text here. Thanks.
|
|

07-24-06, 09:00
|
|
Registered User
|
|
Join Date: Oct 2003
Posts: 1,091
|
|
Quote:
|
Originally Posted by mkggoh
I have a problem on Double variable
eg.
dim d as double
'while a, b, c is value from cell A1, A2, A3, eg. A1=1.5, A2=3.35 , A3=3.65
d = a+b+c
'now, when i compare the value
if d<8.5 then
Msgbox "d is less than 8.5"
end if
'the weird thing happen was, when d=8.5, it will go in to print out 'd is less than 8.5'
but if i set d=8.5, not d=a+b+c, then it won't print that message, because d is not less than 8.5
can anyone tell me why this is happening?
|
It may be that the numbers are actually rounded, and so the sum is not identical to what is seen as the sum of the numbers.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|