Compare stored variable value inside a loop

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
maitresin
Posts: 45
Joined: 20 Mar 2018, 19:33

Compare stored variable value inside a loop

28 Aug 2022, 21:50

Hi,

How to compare a same variable with its previous stored value?

In the below how would File1 accomplish this?
If File1 stored value is higher than its previous stored value continue until new stored value is lower
example: File1 = 1.05, continue, File1 = 2.89, continue, File1 = 3.53, continue, File1 is now 2.91 then it is lower than previous stored value of 3.53 --> activate the fileappend and exit.

Code: Select all

StoredValue := 1.00

Fileread, Tempfile, Tempfile.txt

If (Tempfile > StoredValue)
{
loop
{
sleep, 5000
fileread, file1, file1.txt
; here is the requested help:
If (File1 > previousfile1var continue to loop, if current File1 value is lower than previous File1 value then do the following...)
{
fileappend,
(
%file1%`n
),Final.txt
exitapp
}
}
}
Rohwedder
Posts: 7718
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Compare stored variable value inside a loop

29 Aug 2022, 01:14

Hallo,
try:

Code: Select all

StoredValue := 1.00
Fileread, Tempfile, Tempfile.txt
If (Tempfile > StoredValue)
{
	file1 := 0
	loop
	{
		sleep, 5000
		file1old := file1 ; = previous File1
		fileread, file1, file1.txt
		IF file1 < file1old ;if current File1 value is lower than previous File1 value
		{  ;then do the following...
			fileappend,
			(
			%file1%`n
			),Final.txt
			exitapp
		}
	}
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 164 guests