| View previous topic :: View next topic |
| Author |
Message |
rd2010
Joined: 31 Jan 2010 Posts: 5
|
Posted: Sun Jan 31, 2010 4:18 pm Post subject: Read and write INI files |
|
|
| How do you read all keys in IniRead? |
|
| Back to top |
|
 |
answer4u Guest
|
Posted: Sun Jan 31, 2010 4:39 pm Post subject: |
|
|
| I don't think IniRead has a built-in method for reading all the keys. You could either get creative and find a way to get all the keys ( ie FileRead ), or find a user created INI Library. |
|
| Back to top |
|
 |
SoLong&Thx4AllTheFish
Joined: 27 May 2007 Posts: 4999
|
|
| Back to top |
|
 |
rd2010
Joined: 31 Jan 2010 Posts: 5
|
Posted: Sun Jan 31, 2010 5:01 pm Post subject: |
|
|
I appreciate the fast replys from ya'll. I have been digging and digging with no solution. I have found several scripts but do not know how to specify the file to read from. Here is one:
| Code: |
ReadIni( filename = 0 )
; Read a whole .ini file and creates variables like this:
; %Section%%Key% = %value%
{
Local s, c, p, key, k
if not filename
filename := SubStr( A_ScriptName, 1, -3 ) . "ini"
FileRead, s, %filename%
Loop, Parse, s, `n`r, %A_Space%%A_Tab%
{
c := SubStr(A_LoopField, 1, 1)
if (c="[")
key := SubStr(A_LoopField, 2, -1)
else if (c=";")
continue
else {
p := InStr(A_LoopField, "=")
if p {
k := SubStr(A_LoopField, 1, p-1)
%key%%k% := SubStr(A_LoopField, p+1)
}
}
}
} |
|
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Sun Jan 31, 2010 5:44 pm Post subject: |
|
|
you need to call that function from your code
| Code: | myinifile := "thefileIwant.ini"
ReadIni(myinifile )
listvars
pause |
_________________
(Common Answers) |
|
| Back to top |
|
 |
rd2010
Joined: 31 Jan 2010 Posts: 5
|
Posted: Sun Jan 31, 2010 6:04 pm Post subject: |
|
|
Dude, Thanks.
I am getting there.
Is there any way to make it over look a > as an illegal character? |
|
| Back to top |
|
 |
rd2010
Joined: 31 Jan 2010 Posts: 5
|
Posted: Sun Jan 31, 2010 6:22 pm Post subject: |
|
|
Sorry that wasn't what I needed to ask.
My INI file keys have the same name, so the script is complaining after the first key:
Error:the following variable name contains an illegal character "roomsconf"
myINI file:
[rooms]
conf => 600
conf => 601
conf => 602 |
|
| Back to top |
|
 |
rd2010
Joined: 31 Jan 2010 Posts: 5
|
Posted: Wed Feb 03, 2010 5:15 pm Post subject: |
|
|
| engunneer wrote: | you need to call that function from your code
| Code: | myinifile := "thefileIwant.ini"
ReadIni(myinifile )
listvars
pause |
|
Dude, Thanks.
I am getting there.
Is there any way to make it over look a > as an illegal character?
Sorry that wasn't what I needed to ask.
My INI file keys have the same name, so the script is complaining after the first key:
Error:the following variable name contains an illegal character "roomsconf"
myINI file:
[rooms]
conf => 600
conf => 601
conf => 602 |
|
| Back to top |
|
 |
randallf
Joined: 06 Jul 2009 Posts: 678
|
Posted: Wed Feb 03, 2010 5:40 pm Post subject: |
|
|
myINI file:
[rooms]
conf => 600
conf => 601
conf => 602[/quote]
Why =>? Is it a specific INI format you have to use?
As I understood it and wiki questionably confirms:
| Quote: |
Format
Parameters
The basic element contained in an INI file is the parameter. Every parameter has a name and a value, delimited by an equals sign (=). The name appears to the left of the equals sign.
name=value |
Sorry if I'm off base, haven't worked with INI in AHK yet. |
|
| Back to top |
|
 |
Tuncay n-l-i mobile Guest
|
Posted: Wed Feb 03, 2010 5:57 pm Post subject: |
|
|
| search in this forum for "Basic ini string functions". I am not at home now. Later i show u how to get what u want |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Wed Feb 03, 2010 7:54 pm Post subject: |
|
|
So, I am at home now (may be you guessed right, I am the guest above). Oh I see Hugov has linked to the Basic Ini string library already.^^ cool Hugov
ini_getValue()
With that library you dont need to set global variables for each kez. It provides functions to read keys from variables with the content of ini files. If you do not convert each key into variable, then it can have nearly any character in name. Look in the examples:
- For example you load the whole file into a variable named "ini":
| Code: | | inipath := ini_load(ini, "filename.ini") |
Then you can read in example one keys content:
| Code: | value := ini_getValue(ini, "rooms", "conf")
MsgBox %value% |
ini_exportToGlobals()
It can create global variables for each key also, if needed:
| Code: | ini_exportToGlobals(ini, 0)
ListVars
Msgbox % ini_RecentFileList_File2 |
| Quote: | Remarks:
Creates global variables from ini source. The scheme for building the variables is
following:
> Prefix + Seperator + SectionName + Seperator + KeyName
> ini + _ + Tip + _ + TimeStamp
> --------------------------------------------------------------
> ini_Tip_TimeStamp := "20090716194758"
Standard prefix to every variable is "ini" and all parts are delimited by the
separator "_". The SectionSpaces parameter deletes at default every space from
name of section, because spaces inside ahk variable names are not allowed.
|
It is the best you show your script and explain in detail what you want and need. And show us part of the ini file content. The given example of you is in no way a widely used ini file format. So, the library does not handle that. _________________ {1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <-- |
|
| Back to top |
|
 |
|