Jump to content

Can variables be used in conjunction with macros?


 Share

Recommended Posts

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

I think you mix up two things:

  • Macros are a special kind of variables which are set by AutoIt at run time
  • Values which are to be set by the user (usually values that "configure" your application) are stored in ini files ore the registry
Do you have an example what you try to achieve? Edited 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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

MsgBox(0,"",Execute("@AppDataDir"))

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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

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 - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

well he did explained

He 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 connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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

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 by CGRemakes
Link to comment
Share on other sites

#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 connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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

#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

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 connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...