AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Integers, Floating and math - what am I missing?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Fri Feb 25, 2005 1:20 am    Post subject: Integers, Floating and math - what am I missing? Reply with quote

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? Embarassed


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
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Fri Feb 25, 2005 1:23 am    Post subject: Reply with quote

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
View user's profile Send private message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Fri Feb 25, 2005 4:01 am    Post subject: Reply with quote

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
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Fri Feb 25, 2005 4:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Fri Feb 25, 2005 2:03 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group