FileAppend question

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bcbg92400
Posts: 6
Joined: 03 Oct 2017, 07:56

FileAppend question

22 Oct 2017, 08:24

i wanna get a msgbox each time var is already into the test.txt document

Code: Select all

Random, var, 1, 100
FileAppend, %var%`n, test.txt
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: FileAppend question

22 Oct 2017, 09:24

Code: Select all

F10::
FileRead, content, my.txt
Random, var, 1, 100
If InStr(content,var)
   MsgBox % "Meh, " var " already exists!"
Else
   FileAppend,% var "`n", my.txt
Return
User avatar
theimmersion
Posts: 181
Joined: 09 Jul 2016, 08:34
Location: Serbia

Re: FileAppend question

22 Oct 2017, 10:25

Nvm, BoBo was faster and more accurate, didnt read right. xD
teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: FileAppend question

22 Oct 2017, 10:29

Hi, BoBo,
Consider: 1 and 11, 2 and 22 and so on.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: FileAppend question

22 Oct 2017, 11:39

Here's an attempt.

Code: Select all

q:: ;append random numbers to list, notify of duplicates
oArray := {}
Loop, 100
{
	Random, var, 1, 100
	if oArray.HasKey(var)
	{
		oArray[var]++
		MsgBox, % var " has appeared " oArray[var] " times"
	}
	else
		oArray[var] := 1
	FileAppend, % var "`r`n", %A_Desktop%\z rand num.txt
	Sleep, 100
}
MsgBox, % "done"
return

;==================================================

w:: ;recreate the array from the text file
FileRead, vText, %A_Desktop%\z rand num.txt
oArray := {}
Loop, Parse, vText, `n, `r
{
	vTemp := A_LoopField
	if (vTemp = "")
		continue
	else if oArray.HasKey(vTemp)
		oArray[vTemp]++
	else
		oArray[vTemp] := 1
}
vOutput := ""
for vKey, vValue in oArray
	vOutput .= vKey "`t" vValue "`r`n"
Clipboard := vOutput
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: FileAppend question

22 Oct 2017, 12:17

teadrinker wrote:Hi, BoBo,
Consider: 1 and 11, 2 and 22 and so on.
You're damn right :oops:
Thx to mention it :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Noitalommi_2 and 310 guests