Page 1 of 1

Compare stored variable value inside a loop

Posted: 28 Aug 2022, 21:50
by maitresin
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
}
}
}

Re: Compare stored variable value inside a loop

Posted: 29 Aug 2022, 01:14
by Rohwedder
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
		}
	}
}