Jump to content

Recommended Posts

Posted

AutoIT_Config.txt:

$market="M1" ;Market options: M1, M2, M3.

Script:

#include <File.au3>

Local $configFile = "AutoIT_Config.txt" ;The file to read for setting up the below variables.
Local $fin = FileOpen($configFile, 0) ;Open the file.

Local $market = 0 ;Which market to run the script for.

For $i = 1 To _FileCountLines($configFile) ;Read the configuration textfile into an array.
   $temp = StringSplit(FileReadLine($fin, $i), "=", 0)
_ArrayDisplay($temp)
   If(StringStripWS($temp[1], $STR_STRIPALL) = "$market") Then
      ;Execute($market = $temp[2]) ;Attempt 1
      ;$market = Execute($temp[2]) ;Attempt 2
   EndIf
Next

MsgBox(0, "DEBUG", $market)

FileClose($fin) ;Close the file.

What I am trying to do is have a .exe and a .txt file. This way, people will not need to edit the script and recompile, etc.
Inside the .txt file, you declare the variables. The issue is that the variables have comments to explain the options available.
I don't want to use ; as a delim because the variable I wish to set to may also be a string which has a ; in it.
E.g. $market="Market1; Market2" ;This is a comment.

Basically what I am trying to do is read a line of AutoIT code into the script from a .txt file.

 

Thank you in advance.

Posted

Yup Francesco is right, why not use and .ini file instead of .txt file.

You can change your comment from this ";" to this "<!-- Market options: M1, M2, M3. -->" instead.

Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Posted

I don't think this solves my issue. I want anything to be writable after the first "=" (as long as it's in 1 line in the file.

Correct me if I misunderstood.

Posted (edited)

@IAMK
Could be this a possible solution?
Comments are above the variables, so you can store as much as values you want delimited with ";" :)
Content of the INI File:

[VARIABLES]
;This is a comment for Variable1
Variable1=M1;M2;M3
;This is a comment for Variable2
Variable2=This is the Second Variable

Script:

#include <Array.au3>

Global $strINIFilePath, _
       $strSectionName = "VARIABLES", _
       $arrSectionValues


$strINIFilePath = @ScriptDir & "\Variables.ini"
$arrSectionValues = IniReadSection($strINIFilePath, $strSectionName)
If @error Then
    ConsoleWrite("Error while reading the section '" & $strSectionName & "' from the file '" & $strINIFilePath & "'. Error: " & @error & @CRLF)
Else
    _ArrayDisplay($arrSectionValues)
EndIf

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Posted

So how do you propose the script is going to recognize a comment vs a value?

$market="Market1; Market2" ;This is a comment
vs
$market="Market1; This is a comment

Like the other posters I'd recommend an Ini format, something like:

[Variables]
;~ Market Options: M1, M2, M3
Market = M2

The code:

;~ If the Market Key is missing default to M1
Local $sMarket = IniRead("Variables.ini", "Variables", "Market", "M1")
ConsoleWrite($sMarket & @CRLF)

 

Posted (edited)

The INI would be the default response for KV store, but I would like to see a few more actual examples beyond these two. 

Quote

$market="M1" ;Market options: M1, M2, M3
$market="Market1; Market2" ;This is a comment.

Are your keys going to be stored in the source text with a dollar sign already on them?

Are your values going to already be in double quotes?

If both of those are true i think this becomes a stringop game to speed things up.

edit:  could be regex'd by the person above me, but heres some dirty stringops

;~ $str = '$market="M1" ;Market options: M1, M2, M3'
$str = '$market="Market1; Market2" ;This is a comment.'

assign(stringtrimleft(stringsplit(stringleft($str , stringinstr($str , '"' , 0 , -1)) , "=" , 2)[0] ,1) , stringsplit(stringleft($str , stringinstr($str , '"' , 0 , -1)) , "=" , 2)[1])

msgbox(0, '' , eval("market"))

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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
  • Recently Browsing   0 members

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