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 

running a code from a variable
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Fri Jan 29, 2010 4:45 am    Post subject: running a code from a variable Reply with quote

In this script I can run a code from a text file (code.txt):
Code:
fileappend, msgbox`, hello, code.txt
RunWait, %A_AHKPath% %A_ScriptDir%\code.txt

I wonder if it's possible to run a code from a variable?
For example:
Code:
code = msgbox, hello
run, %code%
Well, this script above doesn't work, but still, is it possible
somehow in AHK to run a code from a variable?
Back to top
View user's profile Send private message
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Fri Jan 29, 2010 4:57 am    Post subject: Reply with quote

Check this thread which makes reference to this one.
_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"

Antonio França
My stuff: Google Profile
Back to top
View user's profile Send private message Visit poster's website
Ace Coder



Joined: 26 Oct 2009
Posts: 361

PostPosted: Fri Jan 29, 2010 4:57 am    Post subject: Reply with quote

It would look more like:
Code:
Code=MsgBox,Test
%Code%

But this isn't legal in AHK, and is called Dynamic Code.
Doing a Forum Search will reveal many past discussions and work-arounds for this.
_________________
Check out the new AHK forum competition!
Back to top
View user's profile Send private message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Fri Jan 29, 2010 5:03 am    Post subject: Reply with quote

Ace Coder wrote:
Doing a Forum Search will reveal many past discussions and work-arounds for this.
I DID the search prior to posting this question. I enetered "running a code from a variable" into the the search line, but none of the 317 titles that it returned matched my request. I mean they were all about some other problems, but not mine. Perhaps, I don't know how to use AHK Search properly.
Back to top
View user's profile Send private message
Guest






PostPosted: Fri Jan 29, 2010 5:09 am    Post subject: Reply with quote

I gave up trying to find a way to do this.

Fortunately for me I found a different method that worked well, my problem was just organizational.

I was trying to do this to get around problems with

Dynamically named functions are possible but unelegant as you must know the number of arguments beforehand:
%MyFunction%(%Arg1%, %Arg2%, %Arg3%, %Arg4%)

From the way I understand it this has to do with AHK not being an object oriented language. You also can't dynamically evaulat efunctions,
Function(Function2(Arg), var2, 12345, "hello") isn't possible.

There are some limitations, I love AHK for it's windows automation capabilities and the style of the language was actually really easy to get into really learning programming from... but it's not a low level language.

As I understand it the overall limitation with what is being discussed here is that the script evaluates portions of the code before running and if code were dynamically callable in this way it wouldn't have been first evaluated properly (or that would have to be emulated)....

To that effect I bet you could make a function you could pass a string to that on-the-fly creates another AHK script file and executes the code. It's not that difficult to return values between AHK scripts from what I've seen.
Back to top
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Fri Jan 29, 2010 5:14 am    Post subject: Reply with quote

MasterFocus wrote:
Check this thread which makes reference to this one.
Just took a look. My, it's so overwhelming! Definitely not for such noobs like me.
It's seems that they are talking to each other there in a language that
they understand perfectly well, while I don't get a word of that.
MasterFocus wrote:
...which makes reference to this one.
In that thread I clicked on download and nothing happened. It appears that
the link is broken.
Back to top
View user's profile Send private message
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Fri Jan 29, 2010 5:24 am    Post subject: Reply with quote

Ok, try this post.
_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"

Antonio França
My stuff: Google Profile
Back to top
View user's profile Send private message Visit poster's website
randallf



Joined: 06 Jul 2009
Posts: 678

PostPosted: Fri Jan 29, 2010 6:03 am    Post subject: Reply with quote

MasterFocus wrote:
Ok, try this post.


Wow well that's one way to do it!
Back to top
View user's profile Send private message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Fri Jan 29, 2010 8:45 am    Post subject: Reply with quote

MasterFocus wrote:
Ok, try this post.
So I have copied that big script into one ahk file and... then what? I am
not sure what I should do so as to proceed? When I click on it, I get a
typical AHK icon on the tray meaning that the script is running, but nothing
more than that. What should I do next in order to store some code into a
variable and run that code from that variable?
Back to top
View user's profile Send private message
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Fri Jan 29, 2010 5:29 pm    Post subject: Reply with quote

That post contains the function.
Instructions can be found on that thread's first post.
_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"

Antonio França
My stuff: Google Profile
Back to top
View user's profile Send private message Visit poster's website
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Sat Jan 30, 2010 11:52 am    Post subject: Reply with quote

MasterFocus wrote:
That post contains the function.
Instructions can be found on that thread's first post.

I am sorry, MasterFocus, I thought that that post was no longer relevant to the
very beginning of thread.
However, I am still missing something there. Look, I still can't run my simple code
using that function:
Code:
; Created by Jonny, with thanks to Rajat for the parsing code.
code = msgbox, hello
execute(Run, code)

{
   global r1,r2,r3,r4,r5,r6,r7

   StringGetPos, cPos, CmdLine, `,
   StringGetPos, sPos, CmdLine, %A_SPACE%
   
   IfGreater, sPos, 0
      IfLess, sPos, %cPos%
         cPos = %sPos%
   
   StringLeft, Command, CmdLine, %cPos%
   cPos ++
   StringTrimLeft, CmdLine, CmdLine, %cPos%
   CmdLine = %CmdLine%
   
   IfEqual, Command,
      Command = %CmdLine%
   
   Loop, Parse, CmdLine, `,, %A_Space%%A_Tab%
      P%A_Index% = %A_LOOPFIELD%
   
   if command not in
(Join
AutoTrim,BlockInput,ClipWait,Control,ControlClick,ControlFocus,
ControlGet,ControlGetFocus,ControlGetPos,ControlGetText,
ControlMove,ControlSend,ControlSendRaw,ControlSetText,CoordMode,
DetectHiddenText,DetectHiddenWindows,Drive,DriveGet,
DriveSpaceFree,Edit,EnvAdd,EnvDiv,EnvMult,EnvSet,EnvSub,EnvUpdate,
ExitApp,FileAppend,FileCopy,FileCopyDir,FileCreateDir,
FileCreateShortcut,FileDelete,FileGetAttrib,FileGetShortcut,
FileGetSize,FileGetTime,FileGetVersion,FileMove,FileMoveDir,
FileRead,FileReadLine,FileRecycle,FileRecycleEmpty,FileRemoveDir,
FileSelectFile,FileSelectFolder,FileSetAttrib,FileSetTime,
GetKeyState,GroupActivate,GroupAdd,GroupClose,GroupDeactivate,Gui,
GuiControl,GuiControlGet,Hotkey,IfEqual,IfNotEqual,IfExist,
IfNotExist,IfGreater,IfGreaterOrEqual,IfInString,IfNotInString,
IfLess,IfLessOrEqual,IfMsgBox,IfWinActive,IfWinNotActive,IfWinExist,
IfWinNotExist,ImageSearch,IniDelete,IniRead,IniWrite,Input,InputBox,
KeyHistory,KeyWait,ListHotkeys,ListLines,ListVars,Menu,MouseClick,
MouseClickDrag,MouseGetPos,MouseMove,MsgBox,OnExit,OutputDebug,
Pause,PixelGetColor,PixelSearch,PostMessage,Process,Progress,Random,
RegDelete,RegRead,RegWrite,Reload,Run,RunAs,RunWait,Send,SendRaw,
SendMessage,SetBatchLines,SetCapslockState,SetControlDelay,
SetDefaultMouseSpeed,SetFormat,SetKeyDelay,SetMouseDelay,
SetNumlockState,SetScrollLockState,SetStoreCapslockMode,SetTimer,
SetTitleMatchMode,SetWinDelay,SetWorkingDir,Shutdown,Sleep,Sort,
SoundBeep,SoundGet,SoundGetWaveVolume,SoundPlay,SoundSet,
SoundSetWaveVolume,SplashImage,SplashTextOn,SplashTextOff,SplitPath,
StatusBarGetText,StatusBarWait,StringCaseSense,StringGetPos,
StringLeft,StringLen,StringLower,StringMid,StringReplace,StringRight,
StringSplit,StringTrimLeft,StringTrimRight,StringUpper,Suspend,
SysGet,Thread,ToolTip,Transform,TrayTip,URLDownloadToFile,
WinActivate,WinActivateBottom,WinClose,WinGetActiveStats,
WinGetActiveTitle,WinGetClass,WinGet,WinGetPos,WinGetText,
WinGetTitle,WinHide,WinKill,WinMaximize,WinMenuSelectItem,
WinMinimize,WinMinimizeAll,WinMinimizeAllUndo,WinMove,WinRestore,
WinSet,WinSetTitle,WinShow,WinWait,WinWaitActive,WinWaitClose,
WinWaitNotActive
)
      return 0
   goto,%command%

AutoTrim:
autotrim,%p1%
return

BlockInput:
blockinput,%p1%
return

ClipWait:
clipwait,%p1%,%p2%
return

Control:
control,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

ControlClick:
controlclick,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

ControlFocus:
controlfocus,%p1%,%p2%,%p3%,%p4%,%p5%
return

ControlGet:
controlget,ov,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return ov

ControlGetFocus:
controlgetfocus,ov,%p1%,%p2%,%p3%,%p4%
return ov

ControlGetPos:
controlgetpos,r1,r2,r3,r4,%p1%,%p2%,%p3%,%p4%,%p5%
return

ControlGetText:
controlgettext,ov,%p1%,%p2%,%p3%,%p4%,%p5%
return ov

ControlMove:
controlmove,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%,%p9%
return

ControlSend:
controlsend,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

ControlSendRaw:
controlsendraw,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

ControlSetText:
controlsettext,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

CoordMode:
coordmode,%p1%,%p2%
return

DetectHiddenText:
detecthiddentext,%p1%
return

DetectHiddenWindows:
detecthiddenwindows,%p1%
return

Drive:
drive,%p1%,%p2%,%p3%
return

DriveGet:
driveget,ov,%p1%,%p2%
return ov

DriveSpaceFree:
drivespacefree,ov,%p1%
return ov

Edit:
edit
return

EnvAdd:
envadd,%p1%,%p2%,%p3%
return

EnvDiv:
envdiv,%p1%,%p2%
return

EnvMult:
envmult,%p1%,%p2%
return

EnvSet:
envset,%p1%,%p2%
return

EnvSub:
envsub,%p1%,%p2%,%p3%
return

EnvUpdate:
envupdate
return

ExitApp:
exitapp
return

FileAppend:
fileappend,%p1%,%p2%
return

FileCopy:
filecopy,%p1%,%p2%,%p3%
return

FileCopyDir:
filecopydir,%p1%,%p2%,%p3%
return

FileCreateDir:
filecreatedir,%p1%
return

FileCreateShortcut:
filecreateshortcut,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%,%p9%
return

FileDelete:
filedelete,%p1%
return

FileGetAttrib:
filegetattrib,ov,%p1%
return ov

FileGetShortcut:
filegetshortcut,%p1%,r1,r2,r3,r4,r5,r6,r7
return

FileGetSize:
filegetsize,ov,%p1%,%p2%
return ov

FileGetTime:
filegettime,ov,%p1%,%p2%
return ov

FileGetVersion:
filegetversion,ov,%p1%
return ov

FileMove:
filemove,%p1%,%p2%,%p3%
return

FileMoveDir:
filemovedir,%p1%,%p2%,%p3%
return

FileRead:
fileread,ov,%p1%
return ov

FileReadLine:
filereadline,ov,%p1%,%p2%
return ov

FileRecycle:
filerecycle,%p1%
return

FileRecycleEmpty:
filerecycleempty,%p1%
return

FileRemoveDir:
fileremovedir,%p1%,%p2%
return

FileSelectFile:
fileselectfile,ov,%p1%,%p2%,%p3%,%p4%
return ov

FileSelectFolder:
fileselectfolder,ov,%p1%,%p2%,%p3%
return ov

FileSetAttrib:
filesetattrib,%p1%,%p2%,%p3%,%p4%
return

FileSetTime:
filesettime,%p1%,%p2%,%p3%,%p4%,%p5%
return

GetKeyState:
getkeystate,ov,%p1%,%p2%
return ov

GroupActivate:
groupactivate,%p1%,%p2%
return

GroupAdd:
groupadd,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

GroupClose:
groupclose,%p1%,%p2%
return

GroupDeactivate:
groupdeactivate,%p1%,%p2%
return

Gui:
gui,%p1%,%p2%,%p3%,%p4%
return

GuiControl:
guicontrol,%p1%,%p2%,%p3%
return

GuiControlGet:
guicontrolget,ov,%p1%,%p2%,%p3%
return ov

Hotkey:
hotkey,%p1%,%p2%,%p3%
return

IfEqual:
ifequal,%p1%,%p2%
   return 1
else
   return 0

IfNotEqual:
ifnotequal,%p1%,%p2%
   return 1
else
   return 0

IfExist:
ifexist,%p1%
   return 1
else
   return 0

IfNotExist:
ifnotexist,%p1%
   return 1
else
   return 0

IfGreater:
ifgreater,%p1%,%p2%
   return 1
else
   return 0

IfGreaterOrEqual:
ifgreaterorequal,%p1%,%p2%
   return 1
else
   return 0

IfInString:
ifinstring,%p1%,%p2%
   return 1
else
   return 0

IfNotInString:
ifnotinstring,%p1%,%p2%
   return 1
else
   return 0

IfLess:
ifless,%p1%,%p2%
   return 1
else
   return 0

IfLessOrEqual:
iflessorequal,%p1%,%p2%
   return 1
else
   return 0

IfMsgBox:
ifmsgbox,%p1%
   return 1
else
   return 0

IfWinActive:
ifwinactive,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

IfWinNotActive:
ifwinnotactive,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

IfWinExist:
ifwinexist,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

IfWinNotExist:
ifwinnotexist,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

ImageSearch:
imagesearch,r1,r2,%p1%,%p2%,%p3%,%p4%,%p5%
return

IniDelete:
inidelete,%p1%,%p2%,%p3%
return

IniRead:
iniread,ov,%p1%,%p2%,%p3%,%p4%
return ov

IniWrite:
iniwrite,%p1%,%p2%,%p3%,%p4%
return

Input:
input,ov,%p1%,%p2%,%p3%
return ov

InputBox:
inputbox,ov,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,,%p8%,%p9%
return ov

KeyHistory:
keyhistory
return

KeyWait:
keywait,%p1%,%p2%
return

ListHotkeys:
listhotkeys
return

ListLines:
listlines
return

ListVars:
listvars
return

Menu:
menu,%p1%,%p2%,%p3%,%p4%,%p5%
return

MouseClick:
mouseclick,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

MouseClickDrag:
mouseclickdrag,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

MouseGetPos:
mousegetpos,r1,r2,r3,r4,%p1%
return

MouseMove:
mousemove,%p1%,%p2%,%p3%,%p4%
return

MsgBox:
if (p2 || p3)
{
   if p4
      msgbox,%p1%,%p2%,%p3%,%p4%
   else
      msgbox,%p1%,%p2%,%p3%
}
else
   msgbox,%p1%
return

OnExit:
onexit,%p1%
return

OutputDebug:
outputdebug,%p1%
return

Pause:
pause,%p1%
return

PixelGetColor:
pixelgetcolor,ov,%p1%,%p2%,%p3%
return ov

PixelSearch:
pixelsearch,r1,r2,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

PostMessage:
postmessage,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

Process:
process,%p1%,%p2%,%p3%
return

Progress:
progress,%p1%,%p2%,%p3%,%p4%,%p5%
return

Random:
random,ov,%p1%,%p2%
return ov

RegDelete:
regdelete,%p1%,%p2%,%p3%
return

RegRead:
regread,ov,%p1%,%p2%,%p3%
return ov

RegWrite:
regwrite,%p1%,%p2%,%p3%,%p4%,%p5%
return

Reload:
reload
return

Run:
run,%p1%,%p2%,%p3%,ov
return ov

RunAs:
runas,%p1%,%p2%,%p3%
return

RunWait:
runwait,%p1%,%p2%,%p3%,ov
return ov

Send:
send,%p1%
return

SendRaw:
sendraw,%p1%
return

SendMessage:
sendmessage,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return errorlevel

SetBatchLines:
setbatchlines,%p1%
return

SetCapslockState:
setcapslockstate,%p1%
return

SetControlDelay:
setcontroldelay,%p1%
return

SetDefaultMouseSpeed:
setdefaultmousespeed,%p1%
return

SetFormat:
setformat,%p1%,%p2%
return

SetKeyDelay:
setkeydelay,%p1%,%p2%
return

SetMouseDelay:
setmousedelay,%p1%
return

SetNumlockState:
setnumlockstate,%p1%
return

SetScrollLockState:
setscrolllockstate,%p1%
return

SetStoreCapslockMode:
setstorecapslockmode,%p1%
return

SetTimer:
settimer,%p1%,%p2%,%p3%
return

SetTitleMatchMode:
settitlematchmode,%p1%,%p2%
return

SetWinDelay:
setwindelay,%p1%
return

SetWorkingDir:
setworkingdir,%p1%
return

Shutdown:
shutdown,%p1%
return

Sleep:
sleep,%p1%
return

Sort:
sort,%p1%,%p2%
return

SoundBeep:
soundbeep,%p1%,%p2%
return

SoundGet:
soundget,ov,%p1%,%p2%,%p3%
return ov

SoundGetWaveVolume:
soundgetwavevolume,ov,%p1%
return ov

SoundPlay:
soundplay,%p1%,%p2%
return

SoundSet:
soundset,%p1%,%p2%,%p3%,%p4%
return

SoundSetWaveVolume:
soundsetwavevolume,%p1%,%p2%
return

SplashImage:
splashimage,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

SplashTextOn:
splashtexton,%p1%,%p2%,%p3%,%p4%
return

SplashTextOff:
splashtextoff
return

SplitPath:
splitpath,%p1%,r1,r2,r3,r4,r5
return

StatusBarGetText:
statusbargettext,ov,%p1%,%p2%,%p3%,%p4%,%p5%
return ov

StatusBarWait:
statusbarwait,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

StringCaseSense:
stringcasesense,%p1%
return

StringGetPos:
stringgetpos,ov,%p1%,%p2%,%p3%,%p4%
return ov

StringLeft:
stringleft,ov,%p1%,%p2%
return ov

StringLen:
stringlen,ov,%p1%
return ov

StringLower:
stringlower,ov,%p1%,%p2%
return

StringMid:
stringmid,ov,%p1%,%p2%,%p3%,%p4%
return ov

StringReplace:
stringreplace,ov,%p1%,%p2%,%p3%,%p4%
return ov

StringRight:
stringright,ov,%p1%,%p2%
return ov

StringSplit:
stringsplit,%p1%,%p2%,%p3%,%p4%
return

StringTrimLeft:
stringtrimleft,ov,%p1%,%p2%
return ov

StringTrimRight:
stringtrimright,ov,%p1%,%p2%
return ov

StringUpper:
stringupper,ov,%p1%,%p2%
return ov

Suspend:
suspend,%p1%
return

SysGet:
sysget,ov,%p1%,%p2%
return ov

Thread:
thread,%p1%,%p2%,%p3%
return

ToolTip:
tooltip,%p1%,%p2%,%p3%,%p4%
return

Transform:
transform,ov,%p1%,%p2%,%p3%
return ov

TrayTip:
traytip,%p1%,%p2%,%p3%,%p4%
return

URLDownloadToFile:
urldownloadtofile,%p1%,%p2%
return

WinActivate:
winactivate,%p1%,%p2%,%p3%,%p4%
return

WinActivateBottom:
winactivatebottom,%p1%,%p2%,%p3%,%p4%
return

WinClose:
winclose,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinGetActiveStats:
wingetactivestats,r1,r2,r3,r4,r5
return

WinGetActiveTitle:
wingetactivetitle,ov
return ov

WinGetClass:
wingetclass,ov,%p1%,%p2%,%p3%,%p4%
return ov

WinGet:
winget,ov,%p1%,%p2%,%p3%,%p4%,%p5%
return ov

WinGetPos:
wingetpos,r1,r2,r3,r4,%p1%,%p2%,%p3%,%p4%
return

WinGetText:
wingettext,ov,%p1%,%p2%,%p3%,%p4%
return ov

WinGetTitle:
wingettitle,ov,%p1%,%p2%,%p3%,%p4%
return ov

WinHide:
winhide,%p1%,%p2%,%p3%,%p4%
return

WinKill:
winkill,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinMaximize:
winmaximize,%p1%,%p2%,%p3%,%p4%
return

WinMenuSelectItem:
winmenuselectitem,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%,%p9%,%p10%,%p11%
return

WinMinimize:
winminimize,%p1%,%p2%,%p3%,%p4%
return

WinMinimizeAll:
winminimizeall
return

WinMinimizeAllUndo:
winminimizeallundo
return

WinMove:
if p1 is integer
{
   if p2 is integer
      winmove,%p1%,%p2%
   else
      winmove,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
}
else
   winmove,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

WinRestore:
winrestore,%p1%,%p2%,%p3%,%p4%
return

WinSet:
winset,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

WinSetTitle:
winsettitle,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinShow:
winshow,%p1%,%p2%,%p3%,%p4%
return

WinWait:
winwait,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinWaitActive:
winwaitactive,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinWaitClose:
winwaitclose,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinWaitNotActive:
winwaitnotactive,%p1%,%p2%,%p3%,%p4%,%p5%
return

suspend,permit

}

Nothing happens this way. What am I doing wrong?
Back to top
View user's profile Send private message
hd0202



Joined: 13 Aug 2006
Posts: 265
Location: Germany

PostPosted: Sat Jan 30, 2010 1:21 pm    Post subject: Reply with quote

Hi,
correct your first lines:
Code:
; Created by Jonny, with thanks to Rajat for the parsing code.
code = msgbox, hello
execute(code)

execute(CmdLine)
{
   global r1,r2,r3,r4,r5,r6,r7
...


Hubert
Back to top
View user's profile Send private message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Sat Jan 30, 2010 3:23 pm    Post subject: Reply with quote

Thank you, Hubert!
Now it works, but I don't understand ... where is "Run" command?
Is it like here "execute" is used instead of "Run"?
Back to top
View user's profile Send private message
Benny-D



Joined: 29 Feb 2008
Posts: 865

PostPosted: Tue Feb 02, 2010 11:38 pm    Post subject: Reply with quote

I am confused again. Why does that function not run this simple code?
Code:
code =
(
msgbox, about to start
x = 1
msgbox, Here is x: %x%

)



Loop, Parse, code, `n
{
execute(A_LoopField)
}
exitapp




execute(CmdLine)
{
   global r1,r2,r3,r4,r5,r6,r7

   StringGetPos, cPos, CmdLine, `,
   StringGetPos, sPos, CmdLine, %A_SPACE%
   
   IfGreater, sPos, 0
      IfLess, sPos, %cPos%
         cPos = %sPos%
   
   StringLeft, Command, CmdLine, %cPos%
   cPos ++
   StringTrimLeft, CmdLine, CmdLine, %cPos%
   CmdLine = %CmdLine%
   
   IfEqual, Command,
      Command = %CmdLine%
   
   Loop, Parse, CmdLine, `,, %A_Space%%A_Tab%
      P%A_Index% = %A_LOOPFIELD%
   
   if command not in
(Join
AutoTrim,BlockInput,ClipWait,Control,ControlClick,ControlFocus,
ControlGet,ControlGetFocus,ControlGetPos,ControlGetText,
ControlMove,ControlSend,ControlSendRaw,ControlSetText,CoordMode,
DetectHiddenText,DetectHiddenWindows,Drive,DriveGet,
DriveSpaceFree,Edit,EnvAdd,EnvDiv,EnvMult,EnvSet,EnvSub,EnvUpdate,
ExitApp,FileAppend,FileCopy,FileCopyDir,FileCreateDir,
FileCreateShortcut,FileDelete,FileGetAttrib,FileGetShortcut,
FileGetSize,FileGetTime,FileGetVersion,FileMove,FileMoveDir,
FileRead,FileReadLine,FileRecycle,FileRecycleEmpty,FileRemoveDir,
FileSelectFile,FileSelectFolder,FileSetAttrib,FileSetTime,
GetKeyState,GroupActivate,GroupAdd,GroupClose,GroupDeactivate,Gui,
GuiControl,GuiControlGet,Hotkey,IfEqual,IfNotEqual,IfExist,
IfNotExist,IfGreater,IfGreaterOrEqual,IfInString,IfNotInString,
IfLess,IfLessOrEqual,IfMsgBox,IfWinActive,IfWinNotActive,IfWinExist,
IfWinNotExist,ImageSearch,IniDelete,IniRead,IniWrite,Input,InputBox,
KeyHistory,KeyWait,ListHotkeys,ListLines,ListVars,Menu,MouseClick,
MouseClickDrag,MouseGetPos,MouseMove,MsgBox,OnExit,OutputDebug,
Pause,PixelGetColor,PixelSearch,PostMessage,Process,Progress,Random,
RegDelete,RegRead,RegWrite,Reload,Run,RunAs,RunWait,Send,SendRaw,
SendMessage,SetBatchLines,SetCapslockState,SetControlDelay,
SetDefaultMouseSpeed,SetFormat,SetKeyDelay,SetMouseDelay,
SetNumlockState,SetScrollLockState,SetStoreCapslockMode,SetTimer,
SetTitleMatchMode,SetWinDelay,SetWorkingDir,Shutdown,Sleep,Sort,
SoundBeep,SoundGet,SoundGetWaveVolume,SoundPlay,SoundSet,
SoundSetWaveVolume,SplashImage,SplashTextOn,SplashTextOff,SplitPath,
StatusBarGetText,StatusBarWait,StringCaseSense,StringGetPos,
StringLeft,StringLen,StringLower,StringMid,StringReplace,StringRight,
StringSplit,StringTrimLeft,StringTrimRight,StringUpper,Suspend,
SysGet,Thread,ToolTip,Transform,TrayTip,URLDownloadToFile,
WinActivate,WinActivateBottom,WinClose,WinGetActiveStats,
WinGetActiveTitle,WinGetClass,WinGet,WinGetPos,WinGetText,
WinGetTitle,WinHide,WinKill,WinMaximize,WinMenuSelectItem,
WinMinimize,WinMinimizeAll,WinMinimizeAllUndo,WinMove,WinRestore,
WinSet,WinSetTitle,WinShow,WinWait,WinWaitActive,WinWaitClose,
WinWaitNotActive
)
      return 0
   goto,%command%

AutoTrim:
autotrim,%p1%
return

BlockInput:
blockinput,%p1%
return

ClipWait:
clipwait,%p1%,%p2%
return

Control:
control,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

ControlClick:
controlclick,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

ControlFocus:
controlfocus,%p1%,%p2%,%p3%,%p4%,%p5%
return

ControlGet:
controlget,ov,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return ov

ControlGetFocus:
controlgetfocus,ov,%p1%,%p2%,%p3%,%p4%
return ov

ControlGetPos:
controlgetpos,r1,r2,r3,r4,%p1%,%p2%,%p3%,%p4%,%p5%
return

ControlGetText:
controlgettext,ov,%p1%,%p2%,%p3%,%p4%,%p5%
return ov

ControlMove:
controlmove,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%,%p9%
return

ControlSend:
controlsend,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

ControlSendRaw:
controlsendraw,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

ControlSetText:
controlsettext,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

CoordMode:
coordmode,%p1%,%p2%
return

DetectHiddenText:
detecthiddentext,%p1%
return

DetectHiddenWindows:
detecthiddenwindows,%p1%
return

Drive:
drive,%p1%,%p2%,%p3%
return

DriveGet:
driveget,ov,%p1%,%p2%
return ov

DriveSpaceFree:
drivespacefree,ov,%p1%
return ov

Edit:
edit
return

EnvAdd:
envadd,%p1%,%p2%,%p3%
return

EnvDiv:
envdiv,%p1%,%p2%
return

EnvMult:
envmult,%p1%,%p2%
return

EnvSet:
envset,%p1%,%p2%
return

EnvSub:
envsub,%p1%,%p2%,%p3%
return

EnvUpdate:
envupdate
return

ExitApp:
exitapp
return

FileAppend:
fileappend,%p1%,%p2%
return

FileCopy:
filecopy,%p1%,%p2%,%p3%
return

FileCopyDir:
filecopydir,%p1%,%p2%,%p3%
return

FileCreateDir:
filecreatedir,%p1%
return

FileCreateShortcut:
filecreateshortcut,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%,%p9%
return

FileDelete:
filedelete,%p1%
return

FileGetAttrib:
filegetattrib,ov,%p1%
return ov

FileGetShortcut:
filegetshortcut,%p1%,r1,r2,r3,r4,r5,r6,r7
return

FileGetSize:
filegetsize,ov,%p1%,%p2%
return ov

FileGetTime:
filegettime,ov,%p1%,%p2%
return ov

FileGetVersion:
filegetversion,ov,%p1%
return ov

FileMove:
filemove,%p1%,%p2%,%p3%
return

FileMoveDir:
filemovedir,%p1%,%p2%,%p3%
return

FileRead:
fileread,ov,%p1%
return ov

FileReadLine:
filereadline,ov,%p1%,%p2%
return ov

FileRecycle:
filerecycle,%p1%
return

FileRecycleEmpty:
filerecycleempty,%p1%
return

FileRemoveDir:
fileremovedir,%p1%,%p2%
return

FileSelectFile:
fileselectfile,ov,%p1%,%p2%,%p3%,%p4%
return ov

FileSelectFolder:
fileselectfolder,ov,%p1%,%p2%,%p3%
return ov

FileSetAttrib:
filesetattrib,%p1%,%p2%,%p3%,%p4%
return

FileSetTime:
filesettime,%p1%,%p2%,%p3%,%p4%,%p5%
return

GetKeyState:
getkeystate,ov,%p1%,%p2%
return ov

GroupActivate:
groupactivate,%p1%,%p2%
return

GroupAdd:
groupadd,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

GroupClose:
groupclose,%p1%,%p2%
return

GroupDeactivate:
groupdeactivate,%p1%,%p2%
return

Gui:
gui,%p1%,%p2%,%p3%,%p4%
return

GuiControl:
guicontrol,%p1%,%p2%,%p3%
return

GuiControlGet:
guicontrolget,ov,%p1%,%p2%,%p3%
return ov

Hotkey:
hotkey,%p1%,%p2%,%p3%
return

IfEqual:
ifequal,%p1%,%p2%
   return 1
else
   return 0

IfNotEqual:
ifnotequal,%p1%,%p2%
   return 1
else
   return 0

IfExist:
ifexist,%p1%
   return 1
else
   return 0

IfNotExist:
ifnotexist,%p1%
   return 1
else
   return 0

IfGreater:
ifgreater,%p1%,%p2%
   return 1
else
   return 0

IfGreaterOrEqual:
ifgreaterorequal,%p1%,%p2%
   return 1
else
   return 0

IfInString:
ifinstring,%p1%,%p2%
   return 1
else
   return 0

IfNotInString:
ifnotinstring,%p1%,%p2%
   return 1
else
   return 0

IfLess:
ifless,%p1%,%p2%
   return 1
else
   return 0

IfLessOrEqual:
iflessorequal,%p1%,%p2%
   return 1
else
   return 0

IfMsgBox:
ifmsgbox,%p1%
   return 1
else
   return 0

IfWinActive:
ifwinactive,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

IfWinNotActive:
ifwinnotactive,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

IfWinExist:
ifwinexist,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

IfWinNotExist:
ifwinnotexist,%p1%,%p2%,%p3%,%p4%
   return 1
else
   return 0

ImageSearch:
imagesearch,r1,r2,%p1%,%p2%,%p3%,%p4%,%p5%
return

IniDelete:
inidelete,%p1%,%p2%,%p3%
return

IniRead:
iniread,ov,%p1%,%p2%,%p3%,%p4%
return ov

IniWrite:
iniwrite,%p1%,%p2%,%p3%,%p4%
return

Input:
input,ov,%p1%,%p2%,%p3%
return ov

InputBox:
inputbox,ov,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,,%p8%,%p9%
return ov

KeyHistory:
keyhistory
return

KeyWait:
keywait,%p1%,%p2%
return

ListHotkeys:
listhotkeys
return

ListLines:
listlines
return

ListVars:
listvars
return

Menu:
menu,%p1%,%p2%,%p3%,%p4%,%p5%
return

MouseClick:
mouseclick,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

MouseClickDrag:
mouseclickdrag,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

MouseGetPos:
mousegetpos,r1,r2,r3,r4,%p1%
return

MouseMove:
mousemove,%p1%,%p2%,%p3%,%p4%
return

MsgBox:
if (p2 || p3)
{
   if p4
      msgbox,%p1%,%p2%,%p3%,%p4%
   else
      msgbox,%p1%,%p2%,%p3%
}
else
   msgbox,%p1%
return

OnExit:
onexit,%p1%
return

OutputDebug:
outputdebug,%p1%
return

Pause:
pause,%p1%
return

PixelGetColor:
pixelgetcolor,ov,%p1%,%p2%,%p3%
return ov

PixelSearch:
pixelsearch,r1,r2,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%
return

PostMessage:
postmessage,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

Process:
process,%p1%,%p2%,%p3%
return

Progress:
progress,%p1%,%p2%,%p3%,%p4%,%p5%
return

Random:
random,ov,%p1%,%p2%
return ov

RegDelete:
regdelete,%p1%,%p2%,%p3%
return

RegRead:
regread,ov,%p1%,%p2%,%p3%
return ov

RegWrite:
regwrite,%p1%,%p2%,%p3%,%p4%,%p5%
return

Reload:
reload
return

Run:
run,%p1%,%p2%,%p3%,ov
return ov

RunAs:
runas,%p1%,%p2%,%p3%
return

RunWait:
runwait,%p1%,%p2%,%p3%,ov
return ov

Send:
send,%p1%
return

SendRaw:
sendraw,%p1%
return

SendMessage:
sendmessage,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return errorlevel

SetBatchLines:
setbatchlines,%p1%
return

SetCapslockState:
setcapslockstate,%p1%
return

SetControlDelay:
setcontroldelay,%p1%
return

SetDefaultMouseSpeed:
setdefaultmousespeed,%p1%
return

SetFormat:
setformat,%p1%,%p2%
return

SetKeyDelay:
setkeydelay,%p1%,%p2%
return

SetMouseDelay:
setmousedelay,%p1%
return

SetNumlockState:
setnumlockstate,%p1%
return

SetScrollLockState:
setscrolllockstate,%p1%
return

SetStoreCapslockMode:
setstorecapslockmode,%p1%
return

SetTimer:
settimer,%p1%,%p2%,%p3%
return

SetTitleMatchMode:
settitlematchmode,%p1%,%p2%
return

SetWinDelay:
setwindelay,%p1%
return

SetWorkingDir:
setworkingdir,%p1%
return

Shutdown:
shutdown,%p1%
return

Sleep:
sleep,%p1%
return

Sort:
sort,%p1%,%p2%
return

SoundBeep:
soundbeep,%p1%,%p2%
return

SoundGet:
soundget,ov,%p1%,%p2%,%p3%
return ov

SoundGetWaveVolume:
soundgetwavevolume,ov,%p1%
return ov

SoundPlay:
soundplay,%p1%,%p2%
return

SoundSet:
soundset,%p1%,%p2%,%p3%,%p4%
return

SoundSetWaveVolume:
soundsetwavevolume,%p1%,%p2%
return

SplashImage:
splashimage,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

SplashTextOn:
splashtexton,%p1%,%p2%,%p3%,%p4%
return

SplashTextOff:
splashtextoff
return

SplitPath:
splitpath,%p1%,r1,r2,r3,r4,r5
return

StatusBarGetText:
statusbargettext,ov,%p1%,%p2%,%p3%,%p4%,%p5%
return ov

StatusBarWait:
statusbarwait,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

StringCaseSense:
stringcasesense,%p1%
return

StringGetPos:
stringgetpos,ov,%p1%,%p2%,%p3%,%p4%
return ov

StringLeft:
stringleft,ov,%p1%,%p2%
return ov

StringLen:
stringlen,ov,%p1%
return ov

StringLower:
stringlower,ov,%p1%,%p2%
return

StringMid:
stringmid,ov,%p1%,%p2%,%p3%,%p4%
return ov

StringReplace:
stringreplace,ov,%p1%,%p2%,%p3%,%p4%
return ov

StringRight:
stringright,ov,%p1%,%p2%
return ov

StringSplit:
stringsplit,%p1%,%p2%,%p3%,%p4%
return

StringTrimLeft:
stringtrimleft,ov,%p1%,%p2%
return ov

StringTrimRight:
stringtrimright,ov,%p1%,%p2%
return ov

StringUpper:
stringupper,ov,%p1%,%p2%
return ov

Suspend:
suspend,%p1%
return

SysGet:
sysget,ov,%p1%,%p2%
return ov

Thread:
thread,%p1%,%p2%,%p3%
return

ToolTip:
tooltip,%p1%,%p2%,%p3%,%p4%
return

Transform:
transform,ov,%p1%,%p2%,%p3%
return ov

TrayTip:
traytip,%p1%,%p2%,%p3%,%p4%
return

URLDownloadToFile:
urldownloadtofile,%p1%,%p2%
return

WinActivate:
winactivate,%p1%,%p2%,%p3%,%p4%
return

WinActivateBottom:
winactivatebottom,%p1%,%p2%,%p3%,%p4%
return

WinClose:
winclose,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinGetActiveStats:
wingetactivestats,r1,r2,r3,r4,r5
return

WinGetActiveTitle:
wingetactivetitle,ov
return ov

WinGetClass:
wingetclass,ov,%p1%,%p2%,%p3%,%p4%
return ov

WinGet:
winget,ov,%p1%,%p2%,%p3%,%p4%,%p5%
return ov

WinGetPos:
wingetpos,r1,r2,r3,r4,%p1%,%p2%,%p3%,%p4%
return

WinGetText:
wingettext,ov,%p1%,%p2%,%p3%,%p4%
return ov

WinGetTitle:
wingettitle,ov,%p1%,%p2%,%p3%,%p4%
return ov

WinHide:
winhide,%p1%,%p2%,%p3%,%p4%
return

WinKill:
winkill,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinMaximize:
winmaximize,%p1%,%p2%,%p3%,%p4%
return

WinMenuSelectItem:
winmenuselectitem,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%,%p9%,%p10%,%p11%
return

WinMinimize:
winminimize,%p1%,%p2%,%p3%,%p4%
return

WinMinimizeAll:
winminimizeall
return

WinMinimizeAllUndo:
winminimizeallundo
return

WinMove:
if p1 is integer
{
   if p2 is integer
      winmove,%p1%,%p2%
   else
      winmove,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
}
else
   winmove,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%,%p7%,%p8%
return

WinRestore:
winrestore,%p1%,%p2%,%p3%,%p4%
return

WinSet:
winset,%p1%,%p2%,%p3%,%p4%,%p5%,%p6%
return

WinSetTitle:
winsettitle,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinShow:
winshow,%p1%,%p2%,%p3%,%p4%
return

WinWait:
winwait,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinWaitActive:
winwaitactive,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinWaitClose:
winwaitclose,%p1%,%p2%,%p3%,%p4%,%p5%
return

WinWaitNotActive:
winwaitnotactive,%p1%,%p2%,%p3%,%p4%,%p5%
return

suspend,permit
}
Back to top
View user's profile Send private message
MasterFocus



Joined: 08 Apr 2009
Posts: 3035
Location: Rio de Janeiro - RJ - Brasil

PostPosted: Wed Feb 03, 2010 1:15 am    Post subject: Reply with quote

It doesn't seem to support the "x = 1" line.
Only commands, I suppose.
_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"

Antonio França
My stuff: Google Profile
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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