AutoHotkey Community

It is currently May 25th, 2012, 5:14 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: October 5th, 2007, 4:15 pm 
Offline

Joined: May 30th, 2006, 11:47 am
Posts: 49
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 4:25 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
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%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 4:31 pm 
Offline

Joined: May 30th, 2006, 11:47 am
Posts: 49
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 4:43 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1832
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 5:49 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 5th, 2007, 6:31 pm 
Offline

Joined: May 30th, 2006, 11:47 am
Posts: 49
Thanks alot. It worked now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2007, 10:18 pm 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2007, 10:34 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1933
Location: Germany
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2009, 1:43 pm 
Offline

Joined: August 25th, 2007, 9:25 pm
Posts: 110
Is it possible to use Custom Section and Key names?

Code:
[TestSection XYZ]
Xkey2=12
Ykey2=23
[XYZ TestSection]
KeyName2=Testit
Key2Name2=DoNotTestIt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2010, 12:38 pm 
Offline

Joined: March 16th, 2010, 2:29 pm
Posts: 12
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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], nothing, toddintr and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group