Jump to content

Expand a macro (@programfilesdir) in a string variable?


Recommended Posts

Hi.

I think the exampe shows what I'm thinking about to do:

; I want to use such an INI file to specify where data shall go to. I want to be able to make use of Autoit @MACROs...
$handle=FileOpen("MyProg.ini",2)
FileWriteLine($handle,"[paths]")
FileWriteLine($handle,"MainPath=@ProgramFilesDir")
FileWriteLine($handle,"SubPath=\This-Time-I-want-it-here\")
FileClose($handle)



$MainPath=IniRead("MyProg.ini","paths","MainPath",@MyDocumentsDir)   ; file: @ProgramFilesDir
$SubPath = IniRead("MyProg.ini","paths","SubPath","\MyProgDataDir\") ; file: \This-Time-I-want-it-here\

$PathPrefix=$MainPath & $SubPath

MsgBox(0,"Path",$PathPrefix)

Howto?

Regards, Rudi.

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

Link to comment
Share on other sites

Thats not how you create an ini file...

$ini = "MyProg.ini"
IniWrite($ini, "paths", "MainPath",@ProgramFilesDir)
IniWrite($ini, "paths", "SubPath","\This-Time-I-want-it-here\")
Link to comment
Share on other sites

Thats not how you create an ini file...

$ini = "MyProg.ini"
IniWrite($ini, "paths", "MainPath",@ProgramFilesDir)
IniWrite($ini, "paths", "SubPath","\This-Time-I-want-it-here\")
Thanks, I know. :P

As I had the INI created manually already, this copy/paste was the easiest way, to "plain write" it from inside the sample script.

I could have added this as well

------- sample MyProg.ini ----------

[paths]

MainPath=@ProgramFilesDir

SubPath=\I-want-it-here\

------- sample MyProg.ini END-----

But that was NOT my question. The question is about an easy way to expand macros inside strings.

So e.g.

$Prefix="@ProgramFilesDir"

Howto expand the /content/ of $Prefix, which is a Autoit Macro right now? :P

Regards, Rudi.

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

Link to comment
Share on other sites

You need to use Execute :P e.g.:

Func _IniReadMacro($fn,$sec,$key,$def)
    Local $return = IniRead($fn,$sec,$key,$def)
    If StringLeft($return,1) = "@" Then
        $return = Execute($return)
        If @error Then Return SetError(@error,0,$def)
    EndIf
    Return $return
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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...