how to save loop number and use it again later?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

how to save loop number and use it again later?

Post by vardipoor.m » Wed Feb 03, 2021 12:19 pm

hi
i use imacros browser 12.5 and windows 10 x64

i have a question:
I want to save the loop number somewhere and start the last loop the next time the macro is run (for when the computer shuts down or something happens to cause it to crash).
The idea that came to my mind is to save in a file, the only problem is that the macro can only store the number in the last line of the text file. In order for me to use the loop number, it must be fixed in a text file on a specific line.
Or another way to read the last line that I did not find the command.
Does anyone know a better way?
thanks
Last edited by vardipoor.m on Thu Feb 04, 2021 9:06 pm, edited 2 times in total.
Thanks to the clever and clean administrator of this forum
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: how to?

Post by chivracq » Wed Feb 03, 2021 4:16 pm

vardipoor.m wrote:
Wed Feb 03, 2021 12:19 pm
hi
i have a question:
I want to save the loop number somewhere and start the last loop the next time the macro is run (for when the computer shuts down or something happens to cause it to crash).
The idea that came to my mind is to save in a file, the only problem is that the macro can only store the number in the last line of the text file. In order for me to use the loop number, it must be fixed in a text file on a specific line.
Or another way to read the last line that I did not find the command.
Does anyone know a better way?
thanks

Maybe an "Idea" to read the Forum Rules when you join a Tech Forum if you are "hoping" for some Help for any of your Threads... :idea:

=> Give a Descriptive Title to your Thread, your "how to?" is a bit useless... :roll:

=> CIM...! :mrgreen: (Read my Sig also...)
(Mentioning your FCI also applies to your 1st Thread...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

Re: how to save loop number and use it again later?

Post by vardipoor.m » Wed Feb 03, 2021 8:33 pm

I noticed and I apologize for writing too short. Was corrected.
Thanks to the clever and clean administrator of this forum
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: how to save loop number and use it again later?

Post by chivracq » Wed Feb 03, 2021 9:21 pm

vardipoor.m wrote:
Wed Feb 03, 2021 8:33 pm
I noticed and I apologize for writing too short. Was corrected.

OK, good-good, this is now "perfect"...! :D
(And you've also mentioned your FCI in your 1st Thread (even if your OS is still missing there, but OK, never mind...), and also posted your Script, which is also very "useful"...)
Hum, correct Spelling is "iMacros" btw... :shock:

Alright, quoting your OP again as it now contains all "needed" Info, and I'll be "sub-quoting" a few Sentences in my Reply...:
vardipoor.m wrote:
Wed Feb 03, 2021 12:19 pm
hi
i use

Code: Select all

imacro browser 12.5 and windows 10 x64


i have a question:
I want to save the loop number somewhere and start the last loop the next time the macro is run (for when the computer shuts down or something happens to cause it to crash).
The idea that came to my mind is to save in a file, the only problem is that the macro can only store the number in the last line of the text file. In order for me to use the loop number, it must be fixed in a text file on a specific line.
Or another way to read the last line that I did not find the command.
Does anyone know a better way?
thanks

"I want to save the loop number somewhere and start the last loop the next time the macro is run (for when the computer shuts down or something happens to cause it to crash)."
=> Yep-yep, very good Practice indeed...! :)

"... is to save in a file..." + "... In order for me to use the loop number, it must be fixed in a text file on a specific line."
=> Yep indeed, that's correct, and the "easiest" Way is to get that "specific Line" = Line_1 (or Line_2 if you want to include some Mini-Header in your File), ah-ah...! :idea:
=> To achieve that Functionality, you will need to save the Loop_Nb to some mini-Temp '.csv' or '.txt' File at the end of your Script, and at the beginning of your Script you will retrieve its Content using the '!DATASOURCE' + '!DATASOURCE_LINE' (=1) Commands to reuse for a "SET !LOOP {{!COL1}}" Statement, together with a 'FILEDELETE' fired on the Temp File to make sure it always only contains 1 or 2 Lines... :idea:

And the 'FILEDELETE' needs to be placed also at the end of your Script, just before the 'SAVEAS', with a mini-'WAIT' Statement between the 2...
If you placed it at the beginning of your Script, after retrieving its Content, you might end up with the Temp-File "disappearing" completely in the case of a "Crash" or if you manually stopped the Script somewhere in the middle, before the next 'SAVEAS' has occurred... :!:

+ '!ERRORIGNORE' is also needed for the very first time you will run/loop the Script and the mini-Temp File won't exist yet... (... or you get some Runtime Error).

Pretty straightforward and not very complicated to implement, I use that Technique myself in several of my Scripts, you can even add some TimeStamp and 'STOPWATCH' Info that could be used for "Logging" Purpose in case "stg went wrong"...

>>>

Another "Idea" would be to enable the 'Profiler' where in case of a Crash, you can retrieve quite a lot of "Info", and I think the Loop_Nb also probably gets stored... Oh..., but hum-hum-hum..., I think it doesn't actually..., I think I remember I had reported "that", but pfff..., that was many years ago, 5 or 6 years ago, I think, so maybe that "Behaviour" then later got "improved", although I don't recall ever seeing anything about that in the Releases Notes for any Version,, and your iMB v12.5 is also already a few years old... :oops:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

Re: how to save loop number and use it again later?

Post by vardipoor.m » Thu Feb 04, 2021 10:39 am

thanks its working like yoghurt ;)
Thanks to the clever and clean administrator of this forum
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: how to save loop number and use it again later?

Post by chivracq » Thu Feb 04, 2021 5:30 pm

vardipoor.m wrote:
Thu Feb 04, 2021 10:39 am
thanks its working like yoghurt ;)

OK, good to hear...! :D , but hum..., can you share the "Yoghurt" with the Community and post your final/working Script (simplified, => demonstrating your Implementation of that Functionality) to make this Thread also useful for other Users...? :idea:

>>>

I don't help any further otherwise, when Users don't share their final/working Script/Solution... :idea:

And I told you the correct Spelling is "iMacros", => can you spell it correctly "from now on"...?, you manage to squeeze 2 Typos in it each time...! :shock: , and this applies to your "next" 2 Threads that I will answer only after you've shared your Sol for this one, and spelled "iMacros" correctly in both...
(I already have "the" Sol for your "Doge" Extraction, I'll need to do some "Thinking" about the "Proxy Bypass", and I "usually" don't help for Proxy but this "Case" is quite "interesting", so you "still have a chance", ah-ah...! :twisted: )

Oh...!, and when posting your Script, pay attention to the "Usability" and "correct Syntax", you seem to be using some FR/GE/SP/PT OS/Browser/Editor that is automatically adding a lot of unnecessary Spaces in your Code when you post it on the Forum, like in your "Doge" Extraction Thread... :!:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
User avatar
vardipoor.m
Posts: 34
Joined: Sun Jan 17, 2021 8:58 am

Re: how to save loop number and use it again later?

Post by vardipoor.m » Thu Feb 04, 2021 5:59 pm

ok no problem
And I told you the correct Spelling is "iMacros"
I will fix them all :mrgreen:
I already have "the" Sol for your "Doge" Extraction
where is the sol please give me a link thanks
Just before you start you should have a txt file named loop-number.txt in the path C: \ Users \ mv \ Documents \ iMacros \ DataSources
Create and enter the desired loop number in it.

Code: Select all

'****this lines adds loop number to !var0*******
set !datasource "loop-number.txt"
set !datasource_line 1
set !loop {{!col1}}
SET !VAR0 EVAL("{{!col1}}+1")

'***you must set datasource to another file before delete loop-number.txt because the macro use loop-number.txt file now, macro cant delete that***

'***main codes here that use loop number as reference***

'***if use next lines before main codes, your loop increase even if main code have had errors you can use next lines after main code to use old loop number if main code had errors***

DELETE NAME=C:\Users\mv\Documents\iMacros\DataSources\loop-number.txt
wait seconds=1
add !extract {{!var0}}
add !extract {{!NOW:mm/dd/yyyy}}
add !extract {{!NOW:hh:nn:ss}}
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\mv\Documents\iMacros\DataSources FILE=loop-number.txt
output like this

1,02/04/2021,20:33:06
Thanks to the clever and clean administrator of this forum
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: how to save loop number and use it again later?

Post by chivracq » Thu Feb 04, 2021 10:19 pm

vardipoor.m wrote:
Thu Feb 04, 2021 5:59 pm
ok no problem
I will fix them all :mrgreen:
Just before you start you should have a txt file named loop-number.txt in the path C: \ Users \ mv \ Documents \ iMacros \ DataSources
Create and enter the desired loop number in it.

Code: Select all

'****this lines adds loop number to !var0*******
set !datasource "loop-number.txt"
set !datasource_line 1
set !loop {{!col1}}
SET !VAR0 EVAL("{{!col1}}+1")

'***you must set datasource to another file before delete loop-number.txt because the macro use loop-number.txt file now, macro cant delete that***

'***main codes here that use loop number as reference***

'***if use next lines before main codes, your loop increase even if main code have had errors you can use next lines after main code to use old loop number if main code had errors***

DELETE NAME=C:\Users\mv\Documents\iMacros\DataSources\loop-number.txt
wait seconds=1
add !extract {{!var0}}
add !extract {{!NOW:mm/dd/yyyy}}
add !extract {{!NOW:hh:nn:ss}}
SAVEAS TYPE=EXTRACT FOLDER=C:\Users\mv\Documents\iMacros\DataSources FILE=loop-number.txt
output like this

1,02/04/2021,20:33:06

"I will fix them all :mrgreen: "
=> Yep, seen them all, good-good, Thanks... :D
You don't seem to "like" Capitals at all, ah-ah...!, but OK, fair enough...
You only "missed" the Path with extra Spaces from your previous Post in this Thread..., but OK, no big deal... :wink:

(And hum, Forum Language is English, even for Profiles and "Internal Communication" when reporting or deleting a Post, "we" don't speak Persian/Arabic on the Forum... :( )

>>>

Alright, Thanks for posting your Script, you've implemented that Functionality very neatly, and mini-Compliment for the Comments inside your Script, together with the clear "Instructions" you gave also... :D

Hum, about "'***you must set datasource to another file before delete loop-number.txt because the macro use loop-number.txt file now, macro cant delete that***", I actually didn't (really) know about that..., I've never encountered that Behaviour myself and never needed to first switch DataSources before being able to delete one...
But I "mostly" use iMacros for FF myself (v8.8.2 + v8.9.7) and the 'FILEDELETE' Command seems to behave quite differently in different Versions and different Browsers... :o :?

Or maybe I did know about it already after all, and you kind of found "the" Explanation together with a Workaround, we had a Thread about 'FILEDELETE' a few years ago, hum, I guess it's probably this one from Feb 2019, where from some "specific" Version, and "By Design", 'FILEDELETE' would only work for Files located in the 'Downloads' iMacros Default Folder and not anymore for Files located in the 'DataSource' Default Folder, and I think that's possibly already the way I implemented myself the Functionality from this Thread, by first saving to the Default 'Downloads' Folder to then specify that Folder/Path for the '!DATASOURCE' Command when I want to "reuse" that Temp-File... And for the 'FILEDELETE' also, of course... :twisted:

>>>

One mini-Remark about your Script, you may want to read that Comment/Recommendation of mine, => the last Paragraph in this Post (about "All Uppercase" Convention), and follow also the Link on the "again" in that Comment... :idea:

>>>

Alright, getting "a bit tired" for the day, but OK, I'll try to answer your Thread about the "Doge" Data-Extraction, I think I had some "easy" Solution for it... 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply