Jump to content
Sign in to follow this  
rudi

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

Recommended Posts

rudi

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!

Share this post


Link to post
Share on other sites
weaponx

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\")

Share this post


Link to post
Share on other sites
yyyy273

$string = (@ProgramFilesDir & "\This-Time-I-want-it-here\")
consolewrite($string)

Is that what you are trying to do?

Share this post


Link to post
Share on other sites
rudi

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!

Share this post


Link to post
Share on other sites
ProgAndy

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.