AutoHotkey Community

It is currently May 27th, 2012, 5:44 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Help with INI file
PostPosted: March 17th, 2010, 4:01 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
I am writing to an INI file for output but, I really don't have a good grasp on the INI File structure. Each time the file writes to the ini, it overwrites the previous entry. What I want it to do is to not overwrite the previous entry, but place the entry in the next line below it.


Code:
Loop
{
Input Key, L1 V, {ScrollLock}{CapsLock}{NumLock}{TAB}{Esc}{BS}{Enter}{PrintScreen}{Pause}{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}
cnt++
}

;~*LButton::
;~*RButton::
;~*MButton::
   cnt++
return

;    ; display current key-press + mouse-click count
;MsgBox %cnt%
;return

=::
myValue := A_Hour ":" A_Min ":" A_Sec "   " A_MM "/" A_DD "/" A_YYYY " " "Keycount" cnt
IniWrite, %myValue%, c:\stats\%A_UserName%.ini,1,cnt
MsgBox %cnt%
;FileAppend %  "," cnt , c:\stats\%A_UserName%.ini
send,{#}
return

#::     ; restart counting
cnt =
return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 4:03 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Create a new key or indeed use fileappend iniwrite, ini format looks like this:

[Settings]
Key1=abc
Key2=def
Key3=ghi

so increment the key value and you can "append" to an ini.

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 4:39 pm 
Offline

Joined: May 12th, 2009, 2:37 pm
Posts: 640
Location: Gloucester UK
Alternatively you can read the existing Ini entry to a variable, append the new text to the end and then write it back to the Ini File

Code:
IniRead, Existing_Entry, c:\stats\%A_UserName%.ini, 1, cnt
New_Entry = %Existing_Entry%`n%myValue%
IniWrite, %New_Entry%, c:\stats\%A_UserName%.ini, 1, cnt


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 6:08 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
Thanks for the quick reply! The file works again! Now on to my second problem. I'm trying to use A_tickcount to measure the time difference between the entries in the INI file. I'm assuming that I would have to write the start time (which actually would be when the equal key was pressed) to a variable, do the math within the script, and post the sum in the ini.

Something like this:
[/code]=::
myValue := A_Hour ":" A_Min ":" A_Sec " " A_MM "/" A_DD "/" A_YYYY " " "Keystrokes " cnt %elapsedtime%
IniWrite, %myValue%, c:\stats\%A_UserName%.ini,%A_Username%,cnt `r
MsgBox %cnt% Keystrokes %ElapsedTime%
send,{#}
StartTime := A_TickCount
ElapsedTime := A_TickCount - StartTime
return
Code:

But, it doesn't work ( it doesn't appear in either the msgbox or the INI file. Any ideas?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 6:45 pm 
Offline

Joined: May 10th, 2009, 7:30 pm
Posts: 45
Code:
=::
FormatTime, timeString, , hh:mm:ss MM/dd/yyyy
myValue := timeString . " Keystrokes " cnt %elapsedtime%
IniWrite, %myValue%, c:\stats\%A_UserName%.ini,%A_Username%,cnt `r ; cnt is never defined in this part so it will be blank until it is.
MsgBox %cnt% Keystrokes %ElapsedTime%
send,{#}
StartTime := A_TickCount ; A_Now is probably the way to go
ElapsedTime := A_TickCount - StartTime
; This will always be zero or very close to it since you're just subtracting the time elapsed in one operation.


For subtracting times you use EnvSub.
http://www.autohotkey.com/docs/commands/EnvSub.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 17th, 2010, 7:59 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
I'm getting an error at line 25.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], Google Feedfetcher, mrhobbeys, rbrtryn and 60 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