 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
canta
Joined: 30 May 2006 Posts: 49
|
Posted: Fri Oct 05, 2007 3:15 pm Post subject: |
|
|
Hmm, why does this inifile work:
[Section]
Keytest1=1
Keytest2=2
and this doesnt:
[Section]
Keytest1=!1
Keytest2=#2
It wont read the modifier symbols, but will write them ok. |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Fri Oct 05, 2007 3:25 pm Post subject: |
|
|
It does work, and I use it in my amun program
| Code: |
IniRead, Out1, test.ini, Section1, Keytest1
IniRead, Out2, test.ini, Section1, Keytest2
IniRead, Out3, test.ini, Section2, Keytest1
IniRead, Out4, test.ini, Section2, Keytest2
MsgBox, %Out1%`n%Out2%`n%Out3%`n%Out4% |
|
|
| Back to top |
|
 |
canta
Joined: 30 May 2006 Posts: 49
|
Posted: Fri Oct 05, 2007 3:31 pm Post subject: |
|
|
I tried using Superfraggle and Engunneer's ini functions in this topic and if the Value include modifier symbols it wont read.
Not sure what i do wrong then. |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Fri Oct 05, 2007 3:43 pm Post subject: |
|
|
| Quote: | I tried using Superfraggle and Engunneer's ini functions in this topic and if the Value include modifier symbols it wont read.
Not sure what i do wrong then. |
oh sorry....they work, but i didnt test whether they work with these ini functions. I use my own ini functions, which dont have this error, or the 1 i posted a few posts back. the problem may be something to do with regex probably the characters arent being escaped or something similar. i try to use string functions more as ive tested them to be faster |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1019 Location: London, UK
|
Posted: Fri Oct 05, 2007 4:49 pm Post subject: |
|
|
There was a slight error in one of the regexpressions
| Code: | initializeini(inifile = "ast.ini"){
global
local key
inisections:=0
loop,read,%inifile%
{
if regexmatch(A_Loopreadline,"\[(\w+)]")
{
inisections+= 1
section%inisections%:=regexreplace(A_loopreadline,"(\[)(\w+)(])","$2")
section%inisections%_keys:=0
}
else if regexmatch(A_LoopReadLine,"(\w+)=(.*)")
{
section%inisections%_keys+= 1
key:=section%inisections%_keys
section%inisections%_key%key%:=regexreplace(A_LoopReadLine,"(\w+)=(.*)","$1")
}
}
} | specifically in red.
It was only matching letters, now will work no matter what you got in there. I've updated the original. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
canta
Joined: 30 May 2006 Posts: 49
|
Posted: Fri Oct 05, 2007 5:31 pm Post subject: |
|
|
| Thanks alot. It worked now. |
|
| Back to top |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 1019 Location: London, UK
|
Posted: Sun Nov 04, 2007 9:18 pm Post subject: |
|
|
Further update:
Code has been slightly updated to work with spaces in keys, and section names. _________________ Steve F AKA Superfraggle
http://r.yuwie.com/superfraggle |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Sun Nov 04, 2007 9:34 pm Post subject: |
|
|
I am using a similiar technique for reading and writing a configuration files. This tech is not a common function, just a way of handling the variables. I dont like global variables, so I declare them as statics. But this needs to be known what is to be readed, which should not be a problem in configuration files.
| Code: | Config(pVar="", pContent="")
{
Static HighscoresPath
SetBatchLines, -1
If pVar =
{
; read variables loops, for example a variable named HighscoresPath
}
Else If pContent !=
{
%pVar% := pContent
pVar := pContent
}
Else
pVar := %pVar%
Return pVar
} |
Usage:
| Code: | Config() ; initialize all variables, call this first
msgbox % Config("HighscoresPath") ; read value
Config("HighscoresPath", "D:\hiscores\hi.ext") ; update value |
Having something similiar integrated into your function could be useful.
Is any way existing to load variable in auto-static mode, like in global? |
|
| Back to top |
|
 |
flashkid
Joined: 25 Aug 2007 Posts: 110
|
Posted: Wed May 20, 2009 12:43 pm Post subject: |
|
|
Is it possible to use Custom Section and Key names?
| Code: | [TestSection XYZ]
Xkey2=12
Ykey2=23
[XYZ TestSection]
KeyName2=Testit
Key2Name2=DoNotTestIt |
|
|
| Back to top |
|
 |
psyclown
Joined: 16 Mar 2010 Posts: 12
|
Posted: Tue Nov 16, 2010 11:38 am Post subject: |
|
|
Thanks for a great script, very useful.
I made a minor change because I had some ini files with keys similair to:
something[0]=1
something[1]=2
something[2]=3
etc...
Those keys would be seen as Sections instead of Keys, so I made my own little change. I'm not a shark in programming and I don't know if this is the easiest way to do it, but it works.
| Code: |
initializeini(inifile){
global
local key,temp
searchString := =
inisections:=0
loop,read,%inifile%
{
StringLen, StringLength, A_Loopreadline
StringTrimRight, SearchString, A_Loopreadline, StringLength-1
if regexmatch(A_Loopreadline,"\[(.*)?]") And SearchString = "["
{
inisections+= 1
section%inisections%:=regexreplace(A_loopreadline,"(\[)(.*)?(])","$2")
section%inisections%_keys:=0
CurSectionName := regexreplace(A_loopreadline,"(\[)(.*)?(])","$2")
AllSections = %AllSections%|%CurSectionName%
}
else if regexmatch(A_LoopReadLine,"(\w+)=(.*)")
{
section%inisections%_keys+= 1
key:=section%inisections%_keys
section%inisections%_key%key%:=regexreplace(A_LoopReadLine,"(\w+)=(.*)","$1")
}
}
}
|
I hope someone can us it |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|