Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to read and write variables to/from a file.
#1
I have a couple of Macros that run all the time on my computer doing various tasks.
I have a variable that increments by one each time the Macro runs. My problem is if I stop the 
Macro and restart it the variable is reset back to 1.  I would like to make it so each time the Macro ends  it increments
by 1 then writes the value to a file. Then the Macro goes back and it sits there waiting for an event to trigger it.
I would like it so if I stop the Macro and restart it the first thing it does is it reads a file and pulls the current value
of the variable so it keeps a running total rather than reseting back to 1.

I hope this explains what I want.

Thanks much in advance.

Captain Hook
#2
simpler would probably be to to use rset to save to registry and rget to retrieve the value from the registry

read more here

rset rget help
#3
If you're set on using a file to do it, this should work.
Code:
Copy      Help
str temp

if(FileExists("%USERPROFILE%\Desktop\test.txt"))     ;; check if file exists
,temp.getfile("%USERPROFILE%\Desktop\test.txt")     ;; stores contents of file to string 'temp'.
,temp=val(temp)+1     ;; evaluate string 'temp' as integer and increment by one.
else
,temp=1     ;; if file does not exist, set # of runs to 1.
temp.setfile("%USERPROFILE%\Desktop\test.txt")     ;; write string 'temp' to file.


Forum Jump:


Users browsing this thread: 1 Guest(s)