Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

INI Class


  • Please log in to reply
32 replies to this topic
zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
I like that idea a lot. I think I'm going to remove comments from keys and instead just support comments above the section like you suggested.

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009

I like that idea a lot. I think I'm going to remove comments from keys and instead just support comments above the section like you suggested.


That would be great. Thank you for Ini Class. I know it will be usefull.

Posted Image

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
Version 0.3:
NEW THIS RELEASE
[*:73uflqiw] Removed adding comments for keys.
[*:73uflqiw] Added comments for sections.

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009

Version 0.3:
NEW THIS RELEASE
[*:wvlov678] Removed adding comments for keys.
[*:wvlov678] Added comments for sections.


Especially with strings I'm not very adept at AHK. Can you give an example of using the new section comment with a multi-line comment?

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
Use `n for a newline in strings.
Taken directly from the example on the first post.
Ini.Foo.__Comment := "This is a simple`nmultiline comment." ; Add a comment to the section foo.


MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I dunno. I could only get it to work as script using as lib. If I use new and compile I get a zero length ini file. I'm baffled.

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
So it works when you use #Include, but not after compiling?
Mind posting your full script?

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009

So it works when you use #Include, but not after compiling?
Mind posting your full script?


I don't even get an empty ini file with this. I must be doing something way off base.

#SingleInstance ignore
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Include cIni.ahk

IniFile = %A_ScriptDir%\IniTest.ini
Ini := new Ini(IniFile)
if !IsObject(Ini)
{
  MsgBox, 4112, , Object Creation Failed!
  ExitApp
}
Ini["Settings"]["__Comment"] := "This is a simple`nmultiline comment.`n"
Ini.Settings.Hotkey.Value := "!F8"

While 1
{
  Sleep,250
}

Ini.Save(IniFile)
Exit


"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
I see two things wrong with your script, one is my fault for not being clear with the update.

The first thing that is wrong is this line
Ini.Settings.Hotkey[color=red].Value[/color] := "!F8"
Ini.Settings.Hotkey := "!F8" ; No need for .Value removed in version 0.3

The second error I found was this part. If you want to sleep for 250 ms remove the while loop.
While 1 ; This will always evaluate to true causing an inifinte loop.
{
  Sleep,250
}

Here is the working script.
#SingleInstance ignore
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#Include cIni.ahk

IniFile = %A_ScriptDir%\IniTest.ini

Ini := new Ini(IniFile)

if !IsObject(Ini)
{
  MsgBox, 4112, , Object Creation Failed!
  ExitApp
}

Ini["Settings"]["__Comment"] := "This is a simple`nmultiline comment.`n"
Ini.Settings.Hotkey := "!F8" ; No need for .Value removed in version 0.3

; While 1 ; This will always evaluate to true causing an inifinte loop.
; {
  ; Sleep,250
; }

Ini.Save(IniFile)
Exit


MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009
I dunno' man. It seems a bit touchy. It makes the .ini file without the While loop. But if I just take the "back tic n" off the end of the line here:

Ini["Settings"]["__Comment"] := "This is a simple`nmultiline comment.`n"

to get this:

Ini["Settings"]["__Comment"] := "This is a simple`nmultiline comment."

It results in this ini file


This is a simple
multiline comment.[Settings]
Hotkey=!F8

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
Thanks for pointing that out, please re-download the class, it should be fixed now.

MilesAhead
  • Members
  • 578 posts
  • Last active: Feb 29 2016 05:15 PM
  • Joined: 21 Jan 2009

Thanks for pointing that out, please re-download the class, it should be fixed now.


Got it. Thanks. :)

"Some people, when confronted with a problem, think I know, I'll use regular expressions.  Now they have two problems."

- Jamie Zawinski


sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
I intend to start using this, and made an improvement (I think...).

I added a subclass for the key, and a function to increment the key (useful for numerical keys). Is this the way to do it?
class __Key
        {
            Increment(n=1)
            {
                this := this + n
                return n
            }
        }

It seemed to work. Usage: ini["Section"]["Key"].Increment() would increase the key value by one.

If someone has some more improvements or ideas for improvements, please share.

zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
Wouldn't this be the same thing?
ini := new Ini()



ini["Section"]["Key"] := 0

ini["Section"]["Key"]++



Msgbox % ini["Section"]["Key"]


sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Wouldn't this be the same thing?

ini := new Ini()

ini["Section"]["Key"] := 0
ini["Section"]["Key"]++

Msgbox % ini["Section"]["Key"]


My bad, when I tried it, it did not work, but that works just fine.