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 

Functions not working in expression

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
tic



Joined: 22 Apr 2007
Posts: 1318

PostPosted: Sat Jan 26, 2008 10:23 am    Post subject: Functions not working in expression Reply with quote

Code:
Var = Hello,world,test

Loop, Parse, Var, `,
MsgBox, %A_LoopField%


works, but:

Code:
Loop, Parse, Function(), `,
MsgBox, %A_LoopField%

Function()
{
   Return, "Hello,world,test"
}


does not
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sat Jan 26, 2008 11:06 am    Post subject: Reply with quote

InputVar wrote:
The name of the variable whose contents will be analyzed. Do not enclose the name in percent signs unless you want the contents of the variable to be used as the name.

_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
tic



Joined: 22 Apr 2007
Posts: 1318

PostPosted: Sat Jan 26, 2008 11:38 am    Post subject: Reply with quote

yes....and....??

the returned value of Function() is the name of the variable.
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5009
Location: imaginationland

PostPosted: Sat Jan 26, 2008 11:45 am    Post subject: Reply with quote

It doesn't matter what is returned, Function() is not a variable name.
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
tic



Joined: 22 Apr 2007
Posts: 1318

PostPosted: Sat Jan 26, 2008 11:58 am    Post subject: Reply with quote

i think it still should be changed as it is inconsistent.

Code:
Loop, % Function()
MsgBox, %A_Index%
Return

Function()
{
   Return, 3
}


works
Back to top
View user's profile Send private message
Obi-Wahn



Joined: 20 Apr 2006
Posts: 23
Location: Vienna

PostPosted: Tue Apr 08, 2008 11:35 am    Post subject: Reply with quote

I was ready to start a topic, but as I can see, there's allready a topic existing.

I'd also be happy, if it'd be possible to use a function or even a literal string in the parse-loop, like a for-loop using in batch.
Because (from my point of view) it would be more failsafe (one variable less) and I like code that doesn't function right, it should also look nice. (call me a geek Very Happy )

Long story short: I'd be pleased if this would be changed.
Thanks
Obi-Wahn
Back to top
View user's profile Send private message Visit poster's website
Rabiator



Joined: 17 Apr 2005
Posts: 264
Location: Sauerland

PostPosted: Tue Apr 08, 2008 3:06 pm    Post subject: Reply with quote

tic wrote:
i think it still should be changed as it is inconsistent.
It is not inconsistent.
As described in the help, Loop takes the value from a variable reference (like %Var%), not from a variable (like Var). Overtaking this term, % Function() is a variable reference.
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 383
Location: Berlin

PostPosted: Tue Apr 08, 2008 9:35 pm    Post subject: Reply with quote

Quote:
Overtaking this term, % Function() is a variable reference.

No this is not a variable reference. The percent sign just puts it into an expression.
Back to top
View user's profile Send private message Send e-mail
Rabiator



Joined: 17 Apr 2005
Posts: 264
Location: Sauerland

PostPosted: Wed Apr 09, 2008 6:20 pm    Post subject: Reply with quote

What is the the correct word for %Var%? Traditional and variable reference are often used in the documentation.
Tuncay wrote:
No this is not a variable reference. The percent sign just puts it into an expression.
You'll agree that in AutoHotkey %Var% is the same as % Var. From the help for MsgBox:
Quote:
This parameter will not be recognized if it contains an expression or a variable reference such as %option%.

Possibly you refer to a comment in the example given in that chapter:
Quote:
By preceding any parameter with "% ", it becomes an expression.
Maybe this is an unfortunate formulation. "% " followed by an expression is a traditional style parameter.

I think this construction was originally most notably intended to easily identify placeholders for string replacement in a text, as you can see it in the options dialogs of many programs. In the sense of write-as-you-speak:
Code:
MsgBox Hello %Name%, how are you?
; is more comfortable than
MsgBox("Hello " Name ", how are you?")
Smile
__________________________________________
Created with BBCodeWriter 7.0 - the one and only Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List 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