CGRemakes 0 Posted November 12, 2010 I was wondering if it's possible to use variables to access the macros found on this list: http://www.autoitscript.com/autoit3/docs/macros.htm For example (I know it doesn't work like this): $variableName = "@AppDataDir" MsgBox(0, "Macro", $variableName) And have it display the info as if you entered just @AppDataDir? I've tried it using Eval(), and it doesn't seem to work either. The reason is, the macro I'm trying to access is not going to be known beforehand. I'm going to be importing info from a text file, so that way people can declare variables in the text file, and I can substitute the real value at execution time. Yes, I could go in and convert all possible macros to variables (meaning something like assigning $appDataDir = @AppDataDir), but that's a fair amount of work. Is there an easier way? Share this post Link to post Share on other sites
water 2,410 Posted November 12, 2010 (edited) I think you mix up two things:Macros are a special kind of variables which are set by AutoIt at run timeValues which are to be set by the user (usually values that "configure" your application) are stored in ini files ore the registryDo you have an example what you try to achieve? Edited November 12, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
bogQ 91 Posted November 12, 2010 MsgBox(0,"",Execute("@AppDataDir")) TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Share this post Link to post Share on other sites
water 2,410 Posted November 12, 2010 But Execute("@AppDataDir") = @AppDataDir I think first the OP has do describe what he wants to achieve. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
bogQ 91 Posted November 12, 2010 well he did explainedHe will allow user to put name in text format like ini file and he will try to call that macro from autoit, but he don't want to use -if-then-else, so that he dont need to add all of expressions TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Share this post Link to post Share on other sites
CGRemakes 0 Posted November 12, 2010 MsgBox(0,"",Execute("@AppDataDir"))That works wonderfully! That will be much easier than manually creating variables for each macro. Share this post Link to post Share on other sites
CGRemakes 0 Posted November 12, 2010 (edited) Ok, I'm running into a small problem, and I'm not sure why. The following is the script I'm using: $var = IniReadSection("C:\Temp\backup_list.ini", @OSVersion) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] $s = StringRegExp($var[$i][1], "%(.+)%", 1) $v = Execute("@" & $s[0]) ConsoleWrite(StringRegExpReplace($var[$i][1], "%.+%", $v) & @CR) Next EndIf Here is the contents of the .ini file I'm importing (I'm on XP, so it jumps to the WIN_XP section): [WIN_XP] file=%ProgramFilesDir%\IBM\Lotus\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.community.sametime/community-config.xml file=%ProgramFilesDir%\IBM\Lotus\Notes\Data\mail\*.nsf file=%ProgramFilesDir%\IBM\Lotus\Notes\Data\*.id file=%ProgramFilesDir%\IBM\Lotus\Notes\Data\bookmarks.nsf file=%ProgramFilesDir%\IBM\Lotus\Notes\notes.ini [WIN_7] file=C:\Users\user\Documents file=C:\Users\user\Pictures For some reason, it's stripping out the "\" after C:. Here's the output I'm getting: C:Program Files\IBM\Lotus\Notes\Data\workspace\.metadata\.plugins\com.ibm.collaboration.realtime.community.sametime/community-config.xml C:Program Files\IBM\Lotus\Notes\Data\mail\*.nsf C:Program Files\IBM\Lotus\Notes\Data\*.id C:Program Files\IBM\Lotus\Notes\Data\bookmarks.nsf C:Program Files\IBM\Lotus\Notes\notes.ini EDIT: Nevermind, I'm sure it's because it's interpretting that as an escape character. I just need to escape the slash. Edited November 12, 2010 by CGRemakes Share this post Link to post Share on other sites
bogQ 91 Posted November 12, 2010 #include <String.au3> #include <Array.au3> $var = IniReadSection("backup_list.ini", @OSVersion) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] $s = _StringBetween($var[$i][1], '%', '%') $c = StringSplit($var[$i][1],"%") ConsoleWrite(Execute("@" & $s[0])&$c[3]&@CR) Next EndIf Does this help? TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Share this post Link to post Share on other sites
CGRemakes 0 Posted November 12, 2010 #include <String.au3> #include <Array.au3> $var = IniReadSection("backup_list.ini", @OSVersion) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] $s = _StringBetween($var[$i][1], '%', '%') $c = StringSplit($var[$i][1],"%") ConsoleWrite(Execute("@" & $s[0])&$c[3]&@CR) Next EndIf Does this help? Which would be more efficient? I know regexp functions are often very slow, so your's may be faster. I got it to work by just escaping any "\" using StringReplace on $v. $var = IniReadSection("C:\Temp\backup_list.ini", @OSVersion) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] $s = StringRegExp($var[$i][1], "%(.+)%", 1) $v = StringReplace(Execute("@" & $s[0]), "\", "\\") ConsoleWrite(StringRegExpReplace($var[$i][1], "%.+%", $v) & @CR) Next EndIf I'm not totally sure why it's required. Does Autoit support pattern matching on the replace string? Share this post Link to post Share on other sites
bogQ 91 Posted November 12, 2010 Dont know whats faster but you can test it with TimerDiff, btw you can use For $i = 1 To $var[0][0] $c = StringSplit($var[$i][1],"%") ConsoleWrite(Execute("@" & $c[2])&$c[3]&@CR) Next _StringBetween was there only for you to have more possibilities TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Share this post Link to post Share on other sites
CGRemakes 0 Posted November 12, 2010 Thank you all for the speedy help. Here is what I came up with: $var = IniReadSection("C:\Temp\backup_list.ini", @OSVersion) If @error Then MsgBox(4096, "", "Error occurred, probably no INI file.") Else For $i = 1 To $var[0][0] $s = StringRegExp($var[$i][1], "%(\w+)%", 3) For $x = 0 To UBound($s) - 1 $v = Execute("@" & $s[$x]) $var[$i][1] = StringReplace($var[$i][1], "%" & $s[$x] & "%", $v) Next ConsoleWrite($var[$i][1] & @CR) Next EndIf I did it that way to allow multiple variables per line at any position. It seems to work very well, and eliminates the second regexp replace that was causing problems and adding pointless overhead. Share this post Link to post Share on other sites