AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with INI file

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
john tuomi



Joined: 22 May 2006
Posts: 150

PostPosted: Wed Mar 17, 2010 3:01 pm    Post subject: Help with INI file Reply with quote

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
Back to top
View user's profile Send private message
SoLong&Thx4AllTheFish



Joined: 27 May 2007
Posts: 4999

PostPosted: Wed Mar 17, 2010 3:03 pm    Post subject: Reply with quote

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 Wiki FAQ
TF : Text files & strings lib, TF Forum
Back to top
View user's profile Send private message
wooly_sammoth



Joined: 12 May 2009
Posts: 634
Location: Gloucester UK

PostPosted: Wed Mar 17, 2010 3:39 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
john tuomi



Joined: 22 May 2006
Posts: 150

PostPosted: Wed Mar 17, 2010 5:08 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
JohnnyTwoTone



Joined: 10 May 2009
Posts: 45

PostPosted: Wed Mar 17, 2010 5:45 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
john tuomi



Joined: 22 May 2006
Posts: 150

PostPosted: Wed Mar 17, 2010 6:59 pm    Post subject: Reply with quote

I'm getting an error at line 25.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group