| View previous topic :: View next topic |
| Author |
Message |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Fri Feb 25, 2005 1:20 am Post subject: Integers, Floating and math - what am I missing? |
|
|
I don't get this - I am expecting my code to display a message box "yay" when A_Index is 6 and 12
The message box never displays...
WHAT am I doing wrong? Also, is there an easier/better way to do this?
| Code: | loop 15
{
Counter6:= A_Index/6
Transform, Counter6Rounded, Round, %Counter6% ; Creates an integer (no decimal point)
Counter6RoundedFloat:=Counter6Rounded/1 ; Adding 0 doesn't convert to floating point. Dividing by 1 does.
If Counter6 = Counter6RoundedFloat
msgbox yay
}
|
|
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Feb 25, 2005 1:23 am Post subject: |
|
|
This seems to work:
| Quote: | loop 15
{
Counter6:= A_Index/6
Transform, Counter6Rounded, Round, %Counter6% ; Creates an integer (no decimal point)
Counter6RoundedFloat:=Counter6Rounded/1 ; Adding 0 doesn't convert to floating point. Dividing by 1 does.
If Counter6 = %Counter6RoundedFloat%
msgbox yay
} |
You could also do this:
| Quote: | loop 15
{
Counter6:= A_Index/6
Transform, Counter6Rounded, Round, %Counter6% ; Creates an integer (no decimal point)
Counter6RoundedFloat:=Counter6Rounded/1 ; Adding 0 doesn't convert to floating point. Dividing by 1 does.
If (Counter6 = Counter6RoundedFloat)
msgbox yay
} |
|
|
| Back to top |
|
 |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Fri Feb 25, 2005 4:01 am Post subject: |
|
|
Thanks jonny-
I just don't get it... but it works... I think I like putting parenthesis around the expression better. And with your code, I don't need to convert Counter6Rounded into floating point (I originally thought that comparing an integer to a floating point was the problem - but converting the integer to floating point before comparing didn't work either!)
If anyone has any links that explains the rules (e.g. that I need to enclose the variable on the right side of an '=' with '%' - or that expressions need to be enclosed in parenthesis...) please let me know! |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Fri Feb 25, 2005 4:39 am Post subject: |
|
|
| Sorry, for me it's just one of those things I know by instinct. You could probably try searching the documentation, there's bound to be something in there. The Variables page might have something. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Fri Feb 25, 2005 2:03 pm Post subject: |
|
|
| SAbboushi wrote: | | If anyone has any links that explains the rules (e.g. that I need to enclose the variable on the right side of an '=' with '%' - or that expressions need to be enclosed in parenthesis...) | The following exists in the FAQ:
| Quote: | When exactly are percent signs used around variable names?
Variable names are always enclosed in percent signs except in cases illustrated in bold below:
1) On the left side of an assignment: Var = 123abc
2) In parameters that are input or output variables: StringLen, OutputVar, InputVar
3) On the left side of non-expression if-statements: If Var1 < %Var2%
4) Everywhere in expressions: a) If (Var1 <> Var2) ... b) Var1 := Var2 + 100 | Concerning parentheses in expressions, they are explained in Expressions and the Quick-start Tutorial
I'm not sure what other places this info should be mentioned to make it clearer. If you think of any, let me know. |
|
| Back to top |
|
 |
|