Sign in to follow this  
Followers 0
rudi

howto Eval("@MacroName") when the Macro's "name" is stored in a string variable?

12 posts in this topic

#1 ·  Posted (edited)

Hi.

I think I've seen this before, but can't find it, as I have no clue, what keywords to search for:

from a INI file I'd like to read a section, specifying e.g. this:

[MODI]
@CommonFilesDir=\Microsoft Shared\MODI\11.0\MSPVIEW.EXE
@CommonFilesDir=\Microsoft Shared\MODI\12.0\MSPVIEW.EXE

[OIS]
@ProgramFilesDir=\Microsoft Office\OFFICE11\OIS.EXE
@ProgramFilesDir=\Microsoft Office\OFFICE12\OIS.EXE
@ProgramFilesDir=\Microsoft Office\OFFICE14\OIS.EXE

inireadsection() will return an array, where the first collumn will hold the macro's name as "string". Several Autoit Macros will return different values for WinXP, Win7-32 and Win7-64. How to "resolve" the macro's "name-in-a-string" to it's value?

Regards, Rudi.

<edit: typo>

<edit2: modified topic title>

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Hi.

Thanks for your reply.

Nope.

Dim $aMyArr[4][2] = [[3], _
        ["@ProgramFilesDir", "Microsoft OfficeOFFICE11OIS.EXE"], _
        ["@ProgramFilesDir", "Microsoft OfficeOFFICE12OIS.EXE"], _
        ["@ProgramFilesDir", "Microsoft OfficeOFFICE14OIS.EXE"]]


$ViewerFound = False

For $i = 1 To $aMyArr[0][0]
    ; I do not know, how to resolve the value of "@programfilesdir",
    ; if I only have this string stored in a variable, as here...
    $foo = $aMyArr[$i][0] & $aMyArr[$i][1] ; <<< this does not work.
    $foo = Eval($aMyArr[$i][0]) & $aMyArr[$i][1] ; <<< this does not work either.
    If FileExists($foo) Then $ViewerFound = $foo
Next

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Opt("ExpandVarStrings", 1)

["@ProgramFilesDir@", "Microsoft OfficeOFFICE11OIS.EXE"]


I see fascists...

Share this post


Link to post
Share on other sites

:D Pefect! :)

Thanks to the ;)

Suggestion @Developers:

Perhaps you might want to update the Autoit Help System, to reference this feature Opt("ExpandVarString",1)

--> "Macro Reference"

--> "Language Reference -> Variables"

--> "Language Reference -> Macros"

A question upon the functionality: What is going on backstage by using this "Double-@" syntax?

"@Programfilesdir@" within a string, used normally just @programfilesdir...

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

:D Pefect! :)

Thanks to the ;)

Suggestion @Developers:

Perhaps you might want to update the Autoit Help System, to reference this feature Opt("ExpandVarString",1)

--> "Macro Reference"

--> "Language Reference -> Variables"

--> "Language Reference -> Macros"

A question upon the functionality: What is going on backstage by using this "Double-@" syntax?

"@Programfilesdir@" within a string, used normally just @programfilesdir...

Regards, Rudi.

Why? The Opt function should be used sparingly. Why not use this instead?

Local  $aArray[4][2] = [[3], _
        [@ProgramFilesDir, 'Microsoft OfficeOFFICE11OIS.EXE'], _
        [@ProgramFilesDir, 'Microsoft OfficeOFFICE12OIS.EXE'], _
        [@ProgramFilesDir, 'Microsoft OfficeOFFICE14OIS.EXE']] ; Use Global or Local, not Dim.
Local $sString = ''

For $i = 1 To $aArray[0][0]
    $sString &= $aArray[$i][0] & $aArray[$i][1] & @CRLF
Next
MsgBox(4096, '', $sString)
If there is a problem with macros reporting different values then provide a small reproducer, say what it should show and report it, but ask here before you submit it to Trac. Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi Guinnes.

Why to update the documentation? Simply because an accurate and complete documentation is 90% of a software's value, imho....

I think it should be up to every coder, what features he/she want's to make use of, don't you think so? ;)

So that the Viewer Programs can be handled by editing an INI file (instead of recompiling the script), I need to read the @macro from that ini. If I don't want to use the @macro, then I would need to write the ini like this:

[modi]
XP-2003-DE=C:ProgrammeGemeinsame DateienMicrosoft SharedMODI11.0MSPVIEW.EXE
XP-2003-EN=C:Program Files...
XP-2007-DE=C:ProgrammeGemeinsame DateienMicrosoft SharedMODI12.0MSPVIEW.EXE
XP-2007-EN=C:Program Files...
XP-2010-DE=C:ProgrammeGemeinsame DateienMicrosoft SharedMODI14.0MSPVIEW.EXE
XP-2010-EN=C:Program Files...
Win7-2007-64=C:Program Files (x86)Common Filesmicrosoft sharedMODI12.0MSPVIEW.EXE
Win7-2007-32=C:Program FilesCommon Filesmicrosoft sharedMODI12.0MSPVIEW.EXE
... all again for the few Win-XP-64 PCs in this LAN...

[OIS]
XP-2003=C:ProgrammeMicrosoft OfficeOFFICE11OIS.EXE
....

When Using the Macro instead, it's far less to take care of:

[MODI]
2003=@CommonFilesDir@Microsoft SharedMODI11.0MSPVIEW.EXE
2007=@CommonFilesDir@Microsoft SharedMODI12.0MSPVIEW.EXE

[OIS]
2003=@ProgramFilesDir@Microsoft OfficeOFFICE11OIS.EXE
2007=@ProgramFilesDir@Microsoft OfficeOFFICE12OIS.EXE
2010=@ProgramFilesDir@Microsoft OfficeOFFICE14OIS.EXE

This will work on WinXP, Win7-32, Win7-64, and any localisation language of Windows. That's the reason, why I will change it later this week, to prevent to run into trouble, when some new "windows flavor" will come into play.

You see the benefit of using the "@Macro@ in a string"? :)

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Why to update the documentation? Simply because an accurate and complete documentation is 90% of a software's value, imho....

Correct, I help with updating the documentation so I know all too well how important it is.

Why not use environment variables instead? Custom or system. If you need an example let me know?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Here's another option...

$foo = Execute($aMyArr[$i][0]) & $aMyArr[$i][1] ; <<< this does work

Share this post


Link to post
Share on other sites

#10 ·  Posted

rudi,

Did you try my suggestion? As I've heard nothing back.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Hi guinnes,

thanks for your suggestion to use env vars. I've tried it, it works.

But I prefer to use the "Opt("ExpandVarStrings", 1)" approach: It's working smoothly, in the INI I can see clearly, what Marcro I'm using, and I personally do *NOT* have any antipathy against using "Opt()" ;) , at least I can't currently see any constraints when making use of this "ExpandVarStrings" ?

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

this even works

Global $sString='AutoItVersion'
ConsoleWrite(Execute('@'&$sString)&@CRLF)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0