How to use !Col function but with a variable ?

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
Reaper
Posts: 15
Joined: Fri Jun 03, 2016 10:26 am

How to use !Col function but with a variable ?

Post by Reaper » Sun Jun 05, 2016 6:53 am

Using iMacros for FF (8.9.7) in FF (46.0.1) , Win 7 x64
and also iMacros 10 (Separately from above)

I am trying to accomplish this : (Described Below)

Suppose i have a text file .

TestDataSource.txt

http://a.com
http://b.com
http://c.com
http://d.com
http://e.com
http://f.com

I am going to the website

http://ascii.cl/url-decoding.htm

Using
URL GOTO=http://ascii.cl/url-decoding.htm

And
SET !VAR1 1

I want to use

TAG POS=1 TYPE=TEXTAREA FORM=NAME:urlform ATTR=NAME:textarea CONTENT={{!COL1}}<BR>

But Like this

{{!COL{!VAR1}}}
ADD !VAR1 1
{{!COL{!VAR1}}}
In this way it should continue as long as the increment occurs

So that it prints
{{!COL1}}
then
{{!COL2}}
then
{{!COL3}}
and so on

Ultimate goal is to create a condition based loop like thing.

How do i achieve this ?
{{!COL{!VAR1}}}
Last edited by Reaper on Mon Jun 06, 2016 10:21 am, edited 1 time in total.
Reaper
Posts: 15
Joined: Fri Jun 03, 2016 10:26 am

Re: How to use !Col function but with a variable ?

Post by Reaper » Sun Jun 05, 2016 7:07 am

So until Now i
came up with this

SET !DATASOURCE E:\Internet<SP>Projects<SP>v2\File<SP>Upload<SP>-<SP>iMacros<SP>-<SP>Resources\DataSource<SP>Test.txt
URL GOTO=http://ascii.cl/url-decoding.htm
TAG POS=1 TYPE=TEXTAREA FORM=NAME:urlform ATTR=NAME:textarea CONTENT={{!COL1}}<BR>{{!COL2}}<BR>{{!COL3}}

So you see there i wrote only upto !col3

But since the number of links in my text file can vary (like from 5 to 50)

I want to implement a way to calculate the number of lines or links
and set it as a reverse counting variable n

and use something like
!col n
!col n-1
.
.
.
!col 1

I want it to print
http://a.com
http://b.com
http://c.com
http://d.com
http://e.com
http://f.com

What / Which part should be modified & How ?
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use !Col function but with a variable ?

Post by chivracq » Mon Jun 06, 2016 5:47 pm

Reaper wrote:Using iMacros for FF (8.9.7) in FF (46.0.1) , Win 7 x64
and also iMacros 10 (Separately from above)

I am trying to accomplish this : (Described Below)

Suppose i have a text file .

TestDataSource.txt

Code: Select all

http://a.com
http://b.com
http://c.com
http://d.com
http://e.com
http://f.com
I am going to the website

http://ascii.cl/url-decoding.htm

Using

Code: Select all

URL GOTO=http://ascii.cl/url-decoding.htm
And

Code: Select all

SET !VAR1 1
I want to use

Code: Select all

TAG POS=1 TYPE=TEXTAREA FORM=NAME:urlform ATTR=NAME:textarea CONTENT={{!COL1}}<BR>
But Like this

Code: Select all

{{!COL{!VAR1}}}
ADD !VAR1 1
{{!COL{!VAR1}}}
In this way it should continue as long as the increment occurs

So that it prints
{{!COL1}}
then
{{!COL2}}
then
{{!COL3}}
and so on

Ultimate goal is to create a condition based loop like thing.

How do i achieve this ?
{{!COL{!VAR1}}}
Reaper wrote:So until Now i came up with this

Code: Select all

SET !DATASOURCE E:\Internet<SP>Projects<SP>v2\File<SP>Upload<SP>-<SP>iMacros<SP>-<SP>Resources\DataSource<SP>Test.txt
URL GOTO=http://ascii.cl/url-decoding.htm
TAG POS=1 TYPE=TEXTAREA FORM=NAME:urlform ATTR=NAME:textarea CONTENT={{!COL1}}<BR>{{!COL2}}<BR>{{!COL3}}
So you see there i wrote only upto !col3

But since the number of links in my text file can vary (like from 5 to 50)

I want to implement a way to calculate the number of lines or links
and set it as a reverse counting variable n

and use something like

Code: Select all

!col n
!col n-1
.
.
.
!col 1
I want it to print

Code: Select all

http://a.com
http://b.com
http://c.com
http://d.com
http://e.com
http://f.com
What / Which part should be modified & How ?
Hum, the '{{!COL{{!VAR1}}}}' Construction doesn't work, I've already filled some EnhReq to implement it in this Thread for example:
chivracq wrote:- Implement a "Super" Built-in Var that could contain Commands like 'OPEN' / 'CLOSE' / 'REFRESH' / 'CLEAR' / etc and other (Built-in) Vars like for example in '{{!COL{{!LOOP}}}}'.
There is a Workaround in '.js' where you can concatenate the String in JavaScript. You have a few Threads on the Forum about that.

But from looking at the Structure of your '.CSV' DataSource, it looks to me that your '.CSV' is "Vertical" with only one Column, simply using '{{!COL1}}' and looping your Macro with '{{!LOOP}}' will let you access the Data from all the Rows..., and it looks to me that it's '!DATASOURCE_LINE' you need to increment instead of '!COLn'.

From there you have several Options...
Either in pure '.iim', you can fetch your Data Row by Row from the DataSource and input it for each Loop in your 'TEXTAREA' Field if the Field lets you append new Data into it or you may have to re-extract it at each Loop to be able to append the new Row, but extracting from some 'INPUT'/'TEXTAREA' Field using the Standard 'TAG' doesn't always work, you might need to use (a Combination with) the 'EVENT' Mode.
Or you can use a (Main) '.js' Script which will drive a first '.iim' Macro looping through the DataSource to fetch the Data Row by Row that the '.js' Script will aggregate before reusing it in some second '.iim' Macro for the Input part into the 'TEXTAREA' Field.

But the Looping part for 50 Rows could take some time, 5-10 sec at least or even up to 30 sec, I would think, for 50 Rows.
There is a simple Trick that allows you to fetch all the 50 Rows with just one single Statement, by manually adding a Double Quote at the complete Beginning and the complete End of your '.CSV' using Notepad, and iMacros will see all the Content between the 2 Double Quotes as one Cell, at least on FF. And I would think that that would handle as well automatically all the '<BR>' Tags..
Another Trick to fetch the Content of the 50 Rows with just one Statement is to save your DataSource as a '.TXT' or '.HTML' File (and not '.CSV') and to open it in your Browser from iMacros in a second TAB to extract all its Content at the 'TABLE' or 'BODY' Level.
- (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...
janib4all
Posts: 132
Joined: Wed Jul 21, 2010 6:44 am
Location: Karachi, Sindh, Pakistan
Contact:

Re: How to use !Col function but with a variable ?

Post by janib4all » Tue Jun 07, 2016 8:40 pm

You need to do something like:

DivHtml = "<div>....</div>';
MyArray = new Array();
Outcomes = new Array();
Outcomes[0] = 'test1';
Outcomes[1] = 'test2';
Outcomes[2] = 'test3';

Increment = -1;
for (loop = 0; loop < Outcomes.length; loop++) {
if (DivHtml.toLowerCase().indexOf(Outcomes[loop]) != -1) {
Increment = Increment + 1;
if (Increment > 0) {
MyArray[Increment] = '&&value' + loop + ":" + Outcomes[loop];
} else {
MyArray[Increment] = Outcomes[loop];
}
}
}

You need to get Html of the Div and loop through all possible fields that you think may occur, the final array "MyArry" will hold the complete instruction like: value1:__value__&&value2:__value__...
Hire the BoT-fReeak!
botspecialist.blogspot.com
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use !Col function but with a variable ?

Post by chivracq » Wed Jun 08, 2016 4:27 am

janib4all wrote:You need to do something like:

Code: Select all

DivHtml = "<div>....</div>';
MyArray = new Array();
Outcomes = new Array();
Outcomes[0] = 'test1';
Outcomes[1] = 'test2';
Outcomes[2] = 'test3';

Increment = -1;
for (loop = 0; loop < Outcomes.length; loop++) {
 if (DivHtml.toLowerCase().indexOf(Outcomes[loop]) != -1) {
   Increment = Increment + 1;
   if (Increment > 0) {
     MyArray[Increment] = '&&value' + loop + ":" + Outcomes[loop];
   } else {
     MyArray[Increment] = Outcomes[loop];
   }
 }
}
You need to get Html of the Div and loop through all possible fields that you think may occur, the final array "MyArry" will hold the complete instruction like: value1:__value__&&value2:__value__...
Yep, but that will still take 5-10-30 sec..., I gave a few Solutions for 0.5 sec instead... (in pure '.iim', ah-ah...! sorry private Joke...!)
- (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...
jjj0817
Posts: 1
Joined: Wed Jun 29, 2016 7:38 am

Re: How to use !Col function but with a variable ?

Post by jjj0817 » Fri Jul 08, 2016 4:35 am

Code: Select all

SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; var row=\"{{tri}}\"-1;var cloumn=\"{{tdj}}\";if(s==\"{{!COL\"+\"{{tri}}\"+\"}}\") s; else MacroError(row+\"科目编码数据不一致\")")
You can use EVAL to append string ti achive "!COL{{N}}",like my code' s==\"{{!COL\"+\"{{tri}}\"+\"}}\" ',it's look like SQL inject :D
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to use !Col function but with a variable ?

Post by chivracq » Fri Jul 08, 2016 2:22 pm

jjj0817 wrote:

Code: Select all

SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; var row=\"{{tri}}\"-1;var cloumn=\"{{tdj}}\";if(s==\"{{!COL\"+\"{{tri}}\"+\"}}\") s; else MacroError(row+\"科目编码数据不一致\")")
You can use EVAL to append string ti achive "!COL{{N}}",like my code' s==\"{{!COL\"+\"{{tri}}\"+\"}}\" ',it's look like SQL inject :D
Yep, your Method is good to concatenate the "{{!COLn}}" String but iMacros stops there and doesn't try to go and fetch the Value of the Var.
This is actually a Workaround/Equivalent used to get the same like the '#NOVAR#' Command.

This simple Macro will demonstrate it: (Just loop it 3 or more times...)

Code: Select all

SET !VAR1 "VAR1 Blabla...!"
SET !VAR2 "VAR2 Bloblo...!"
SET !VAR3 "VAR3 Blublu...!"

SET Var_N EVAL("var r='{{!LOOP}}'; var x='{{!VAR' + r + '}}'; x;")
PROMPT Var_N:<SP>_{{Var_N}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.1.1 (=FF43), Win10-x64 + iMacros for FF v8.9.6, FF45, Win10-x64.)
- (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