Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Hello, I was wondering how come these two expression have different results Code: -------------------- 12 - (previousSickMonth - employmentMonth + tempMonth) -------------------- Code: -------------------- 12 - previousSickMonth - employmentMonth + tempMonth -------------------- The first one gives me the correct answer that I want. But it doesn't make sense to me how come there would be a difference. All the operators are just subtraction and addition, and it shouldn't be based on any form of precedence. Is there some kind of VBA difference from other programming languages I am missing here? -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What answers do you get, and from what inputs?
They should give the same result, unless perhaps your inputs are of different types and precisions. Tim. "FCC" wrote in message ... Hello, I was wondering how come these two expression have different results Code: -------------------- 12 - (previousSickMonth - employmentMonth + tempMonth) -------------------- Code: -------------------- 12 - previousSickMonth - employmentMonth + tempMonth -------------------- The first one gives me the correct answer that I want. But it doesn't make sense to me how come there would be a difference. All the operators are just subtraction and addition, and it shouldn't be based on any form of precedence. Is there some kind of VBA difference from other programming languages I am missing here? -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The expressions are not the same, hence the different results. If you
multiply out the brackets in the first example, what do you get ? It's not VBA, it's your maths. NickHK "FCC" wrote in message ... Hello, I was wondering how come these two expression have different results Code: -------------------- 12 - (previousSickMonth - employmentMonth + tempMonth) -------------------- Code: -------------------- 12 - previousSickMonth - employmentMonth + tempMonth -------------------- The first one gives me the correct answer that I want. But it doesn't make sense to me how come there would be a difference. All the operators are just subtraction and addition, and it shouldn't be based on any form of precedence. Is there some kind of VBA difference from other programming languages I am missing here? -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You get a difference of 2 * ABS(employmentMonth - tempMonth) between the 2
expressions ? NickHK "FCC" wrote in message ... Hello, I was wondering how come these two expression have different results Code: -------------------- 12 - (previousSickMonth - employmentMonth + tempMonth) -------------------- Code: -------------------- 12 - previousSickMonth - employmentMonth + tempMonth -------------------- The first one gives me the correct answer that I want. But it doesn't make sense to me how come there would be a difference. All the operators are just subtraction and addition, and it shouldn't be based on any form of precedence. Is there some kind of VBA difference from other programming languages I am missing here? -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Try some input like: previousSickMonth = 1 employmentMonth = 5 tempMonth = 2 With Code: -------------------- tempMonth = 12 - previousSickMonth - employmentMonth + tempMonth -------------------- I got 8. With Code: -------------------- tempMonth = 12 - (previousSickMonth - employmentMonth + tempMonth) -------------------- I got 14. But I know what the problem is, if you work out the bracklets first, you could get an negative number. Obviously a subtract a negative number and you get a positive number, hence the difference. But to be honest, this is the first time I've ever experienced a difference in two expressions that consisted of only addition and subtraction operators. I've always been under the impression that bracklets don't mean anything with only addition and subtraction operators. I guess I was wrong. -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you think of it as:
tempMonth = 12 - 1 * (previousSickMonth - employmentMonth + tempMonth) does it make it more clear ? NickHK "FCC" wrote in message ... Try some input like: previousSickMonth = 1 employmentMonth = 5 tempMonth = 2 With Code: -------------------- tempMonth = 12 - previousSickMonth - employmentMonth + tempMonth -------------------- I got 8. With Code: -------------------- tempMonth = 12 - (previousSickMonth - employmentMonth + tempMonth) -------------------- I got 14. But I know what the problem is, if you work out the bracklets first, you could get an negative number. Obviously a subtract a negative number and you get a positive number, hence the difference. But to be honest, this is the first time I've ever experienced a difference in two expressions that consisted of only addition and subtraction operators. I've always been under the impression that bracklets don't mean anything with only addition and subtraction operators. I guess I was wrong. -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() A little bit, but in reality everything is mulitplied by 1 so still doesn't really bring out the essence of the bracklets. -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 12 - (previousSickMonth - employmentMonth + tempMonth) =12 - 1 * (previousSickMonth - employmentMonth + tempMonth) =12 - previousSickMonth + employmentMonth - tempMonth <<< Note change of sign < 12 - previousSickMonth - employmentMonth + tempMonth NickHK "FCC" wrote in message ... A little bit, but in reality everything is mulitplied by 1 so still doesn't really bring out the essence of the bracklets. -- FCC ------------------------------------------------------------------------ FCC's Profile: http://www.excelforum.com/member.php...o&userid=35888 View this thread: http://www.excelforum.com/showthread...hreadid=557981 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
i have expression - E$5 what is the difference from E5? | Excel Discussion (Misc queries) | |||
value expression | Excel Worksheet Functions | |||
need help with expression | Excel Discussion (Misc queries) | |||
Expression | New Users to Excel | |||
charting a difference of 2 columns' w/o adding a difference column | Charts and Charting in Excel |