CGRemakes Posted November 12, 2010 Share 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? Link to comment Share on other sites More sharing options...
water Posted November 12, 2010 Share 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
bogQ Posted November 12, 2010 Share 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. Link to comment Share on other sites More sharing options...
water Posted November 12, 2010 Share 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
bogQ Posted November 12, 2010 Share 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. Link to comment Share on other sites More sharing options...
CGRemakes Posted November 12, 2010 Author Share Posted November 12, 2010 MsgBox(0,"",Execute("@AppDataDir"))That works wonderfully! That will be much easier than manually creating variables for each macro. Link to comment Share on other sites More sharing options...
CGRemakes Posted November 12, 2010 Author Share 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 Link to comment Share on other sites More sharing options...
bogQ Posted November 12, 2010 Share 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. Link to comment Share on other sites More sharing options...
CGRemakes Posted November 12, 2010 Author Share 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? Link to comment Share on other sites More sharing options...
bogQ Posted November 12, 2010 Share 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. Link to comment Share on other sites More sharing options...
CGRemakes Posted November 12, 2010 Author Share 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now