Jump to content

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

ahkbook - a free online book for AutoHotkey


  • Please log in to reply
115 replies to this topic
GuestFromMinsAgo
  • Guests
  • Last active:
  • Joined: --
Not sure if there belongs a space

If (VarContaining35 & 32)
http://maul-esel.git... ... -bits.html

maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
Thanks a lot. I fixed the "built-in" thing (really was sure it has to be written in one word) and the "yu". I don't see the problem with "whereas" though (reference).

The VarContaining35 is correct as far as I can see (I haven't written that part myself). It means a variable which contains the value 35 and is therefore named like that.
Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

Guest
  • Guests
  • Last active:
  • Joined: --

I don't see the problem with "whereas" though (reference).

The VarContaining35 is correct as far as I can see (I haven't written that part myself). It means a variable which contains the value 35 and is therefore named like that.

Never heard of whereas before, sorry.

About the variable, I wasn't sure. But nice to hear that you fixed all the built-ins. :)


By the way, the red links don't have an own site, yet or why do they link to the main page?

maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
Yeah, that's because most of the planned articles have not yet been written. And unfortunately, I can't say when I get around to write on it again :( But everyone who wants to contribute, report errors or add articles is most welcome to do so (via github, PM, mail or this thread). :D
Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

GuestFromBefore
  • Guests
  • Last active:
  • Joined: --
For me, the usage of the ini, is very useful, important and enjoyable to use.
So I thought about giving you some 'basic post' which you could edit for your own needs. It hopefully reduces the time you'll need to add it to the book.

INI
_________

An INI file is a in section seperated configuration file which allows you to store different data in one or more sections.
The structure of an ini file is simple:

[StructureName]
Key1=Name
Key2=Age
Key3=EyeColour
[StructureName2]
Key1=Name
Key2=Age
Key3=EyeColour

It's perfect for storing numbers or important information which the program or the script needs. It also provides a good overview.

IniWrite
As the name already says, you can use this command to write values into an ini.
The command's structure is:
IniWrite, Value, Filename, Section, Key
The value can be either a number or letters. Please note, you can not keep this emty - instead use %A_Space%, in case you don't want to add something.
Secondly, you need to add the filepath of the ini file, so the script can add the value to it. It can be either normal string or a variable like %A_desktop%\example.ini.
The section, as above already mentioned, is basically the data block's name. The script needs it to work out which Key (see example) it should use because the ini file allows you to use duplicated key names.
And finally, the key, you add it to retrieve the piece of data which you previously added to it.

An example:
IniWrite,Tim,%A_desktop%\example.ini,Member1,Key1

The result in the ini would look like:

Member1
Key1=Tim


IniRead
Imagine, you would have a script which allows the user to add details of a person to an ini.
The IniWrite was a good example for it.
But how would you get these details to show up without opening the ini file?

The IniRead command allows you to access it - and it isn't even complicated!
The command's structure is basically as the IniWrite one with 2 differences: the outputvar (and the default - later)
IniRead, OutputVar, Filename, Section, Key [, Default]

As always, it starts with the command itself, followed by the variable where to store the ini's key's data (e.g the name of member1).
Then comes the file name, where it will access the ini.
Followed by the section and the key.

Let's take a look on the iniwrite example again:

Member1
Key1=Tim

How would you retrieve the string Tim?
Already figured it out? Good.

IniRead,Name,%A_desktop%\example.ini,Member1,Key1
MsgBox % Name ; Will show you the name you retrieved - which will be: Tim

Or you retrieve the data of the key1 from the second member, then it could be:
IniRead,Name,%A_desktop%\example.ini,Member2,Key1
Same key name but a different block name.


So now, the member left your community but the details about him are still in the ini file - how would you delete them? - manually? No.
We'll, of course, use a command again.

This time it's IniDelete.
The command's structure:
IniDelete, Filename, Section [, Key]
As you already saw, it contains this []. You've learned before that these indicate that the command part enclosed by them is optional.

Back to our example:

Member1
Key1=Tim

We now want to delete his name:
IniDelete,%A_desktop%\example.ini,Member1,Key1
This will only delete Key1 of the section 'Member1'.
To delete the whole section, we simply remove the key name:
IniDelete,%A_desktop%\example.ini,Member1

Full example script:
; You can even use the output of a msgbox or a control to write it into the ini.
; Imagine an user inputed the age of Tim in an InPutBox, we'll now use it in the command.
; AgeOfTim (the variable we use for the output contains 21
IniWrite,Tim,%A_desktop%\example.ini,Member1,Name
IniWrite,%AgeOfTim%,%A_desktop%\example.ini,Member1,Age
IniWrite,blue,%A_desktop%\example.ini,Member1,EyeColour

IniWrite,Tom,%A_desktop%\example.ini,Member1,Name
IniWrite,Age,%A_desktop%\example.ini,Member1,Age
IniWrite,green,%A_desktop%\example.ini,Member1,EyeColour

; We'll now read the ini's data 
IniRead,Name,%A_desktop%\example.ini,Member1,Name ; You can use the same name as the output & key name
; But make sure, you use another name for the second user if you are retrieving the information at once without using them right after (example afer this one)
IniRead,Age,%A_desktop%\example.ini,Member1,Age
IniRead,EyeColour,%A_desktop%\example.ini,Member1,EyeColour

IniRead,Name2,%A_desktop%\example.ini,Member2,Name
IniRead,Age2,%A_desktop%\example.ini,Member2,Age
IniRead,EyeColour2,%A_desktop%\example.ini,Member2,EyeColour

MsgBox % "Member1: " Name
             . "His age: " Age
             . "His eye colour: " eyecolour
             . "Member2: " Name2
             . "His age: " Age2
             . "His eye colour: " eyecolour2
IniDelete,%A_desktop%\example.ini,Member1
IniDelete,%A_desktop%\exmaple.ini,Member2 ; ini is now emty.

In one of the comments I said, it wouldn't be smart to use the same variable to retrieve a content of 2 different blocks/sections.
Let's say, the script saves Tim in the variable Name but then it goes to the second section and saves Tom in the same variable - what do you think does the variable Name now contain?
Right, it contains Tom because it automatically overwrote the first content.


I actually like the example with the member of a community because the ini is made for details and stuffs which are detailed retrieved.
Up to you to use it. Examples aren't tested and might contain wrong stuffs, too.

As I said, it's basically to give you some kind of starting point.

Have fun.

maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
Thanks a thousand times! I have converted the post to markdown, will do a few edits the coming week (and check the markdown again). I hope to be able to post it soon. If you wish, I would also be happy to add you to the list of contributors (with (nick-)name & homepage link).
Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

GuestFromBefore
  • Guests
  • Last active:
  • Joined: --
If you don't mind, you could add aRt)Y as name.

I'll probably try to make a post about creating a GUI, although it's not on your list.
But it's a huge area anyway.

otherGuest
  • Guests
  • Last active:
  • Joined: --
@maul.esel: why not add the following

## Tip

If you do not want to store the information in a seperate INI file you can use the
script file itself by adding a commented section with the proper INI sections and keys.
Use the built-in variable A_ScriptName. Of course this will only work for uncompiled scripts.

**example**

; your script

; to read:
IniRead, Key1, %A_ScriptName%, settings, key1

; to write:
IniWrite, %key1%, %A_ScriptName%, settings, key1

/*
[settings]
key1=value
key2=value

*/



Uberi
  • Moderators
  • 1119 posts
  • Last active: May 02 2015 06:05 PM
  • Joined: 23 Aug 2010

@maul.esel: why not add the following

## Tip

If you do not want to store the information in a seperate INI file you can use the
script file itself by adding a commented section with the proper INI sections and keys.
Use the built-in variable A_ScriptName. Of course this will only work for uncompiled scripts.

**example**

; your script

; to read:
IniRead, Key1, %A_ScriptName%, settings, key1

; to write:
IniWrite, %key1%, %A_ScriptName%, settings, key1

/*
[settings]
key1=value
key2=value

*/


I'd use A_ScriptFullPath in case A_WorkingDir was changed.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
Be sure to also leave a note that this will not work when compiled.

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010

On NTFS systems, you can store the ini file in a separate filestream, even when compiled.