Jump to content

Config file


Recommended Posts

I make my own config files with #include.

Example, I like to have my own defaults.

; myfile.au3
; get my defaults
#include "config.txt"

; config.txt
AutoItSetOption("ExpandEnvStrings", 0);1 = expand environment variables (similar to AutoIt v2)
AutoItSetOption("MouseCoordMode", 0);1 = absolute screen coordinates (default)
AutoItSetOption("PixelCoordMode", 0);1 = absolute screen coordinates (default)
AutoItSetOption("RunErrorsFatal", 0);0 = silent error (@error set to 1)
AutoItSetOption("SendKeyDelay", 10);Time in millseconds to pause (default=10).
AutoItSetOption("WinWaitDelay", 250);Time in millseconds to pause (default=250).
AutoItSetOption("WinDetectHiddenText", 0);1 = Detect hidden text
AutoItSetOption("WinTitleMatchMode", 1);2 = Match any substring in the title

The danger in this is that anyone changing the config file will execute whatever autoit commands are in it, but is nice for little things if you are the only user.

While this is fine for little things, If I was making a config file for giving someone a macro, I would use. FileReadLine($file)

; getx.au3
; Get X from config file 
$file = FileOpen("config.ini", 0)
; Check if file opened for reading OK
If $file = -1 Then
     MsgBox(0, "Error", "Unable to open file.")
     Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
     $line = FileReadLine($file)
     If @error = -1 Then
         ExitLoop
     EndIf
if StringLeft($line, 2)="X=" then
$x=StringTrimLeft( $line, 2 ) 
; if X is found, This displays
     MsgBox(0, "X is found, Value is", $x)
else
; if X= is not found, display this
     MsgBox(0, "Showing useless Line", $line)
     endif
Wend
FileClose($file)

; config.ini
Bob=friend
X=45
Y=20

Using the above example, and an array or two, you can set all the variables you wish, while keeping the safety of your autoit exe. You can even make it a function if you wish.

Hope that is what you were asking...

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

  • 11 years later...

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