IF THEN ELSE commands

Discussions and Tech Support related to automating the iMacros Browser or Internet Explorer from any scripting and programming language, such as VBS (WSH), VBA, VB, Perl, Delphi, C# or C++.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

IF THEN ELSE commands

by dcaba79 on Thu Mar 17, 2016 12:41 pm

i've tried to find a solution for my current macro, I have a csv with some information I want to use if command based on value of the csv file.

FIREFOX 44.0.2
OS Windows 10
IMACRO VERSION BUILD=8961227


'URL GOTO=https://website.com/asp.aspx
SET !DATASOURCE "MY CSV FILE LOCATION"
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

IF {{!COL6}} = C
THEN
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_cbCancel CONTENT=YES
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_ddlCancelReasons CONTENT=%55
ELSE
IF {{!COL6}} = N
THEN
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_cbCancel CONTENT=YES
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_ddlCancelReasons CONTENT=%1
ELSE
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbConfirm CONTENT=YES
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtVehicleID CONTENT={{!COL6}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtDriverID CONTENT={{!COL7}}
Last edited by dcaba79 on Fri Mar 18, 2016 6:34 am, edited 3 times in total.
dcaba79
 
Posts: 4
Joined: Mon Nov 23, 2015 12:19 pm

Re: IF THEN ELSE commands

by chivracq on Thu Mar 17, 2016 1:44 pm

dcaba79 wrote:i've tried to find a solution for my current macro, I have a csv with some information I want to use if command based on value of the csv file.

Code: Select all
VERSION BUILD=8940826 RECORDER=FX
'URL GOTO=https://website.com/asp.aspx
SET !DATASOURCE "MY CSV FILE LOCATION"
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

IF {{!COL6}} = C
THEN
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_cbCancel CONTENT=YES
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_ddlCancelReasons CONTENT=%55
ELSE
IF {{!COL6}} = N
THEN
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_cbCancel CONTENT=YES
TAG POS=1 TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_{{!COL14}}_ddlCancelReasons CONTENT=%1
ELSE
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbConfirm CONTENT=YES
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtVehicleID CONTENT={{!COL6}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtDriverID CONTENT={{!COL7}}

FCIM...! :mrgreen: (Always mention your FCI when you open a Thread...)

Many-many Threads on the Forum about 'IF THEN ELSE'...

Normal way to achieve some Conditional Behaviour with iMacros is to put the Conditional Logic in a (main) '.js' Script...

But in your Case, but only 2-3 Statements per Condition and they are relatively similar, you could easily use 'EVAL()' (+ 'case' or 'if else') to spit out a "1" / "0" to use for 'POS=n' per Block/Condition and/or the '_cbCancel'/'_cbConfirm' etc Strings to use for the 'TAG' Statements. (+ '!ERRORIGNORE' and a short '!TIMEOUT_STEP'.)
Search my Posts on 'Conditional Behaviour" for more Info and Examples if you want to go this way... (You have a Thread called "Decision making... etc" in the 'Howto's: Useful Macros' Sub-Forum where I explained the Technique and maintain a List of useful Threads with interesting Examples...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6477
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: IF THEN ELSE commands

by dcaba79 on Thu Mar 17, 2016 5:49 pm

I will give this a try, got a idea of what you are saying, I will create something with eval to activate only the lines need according to the results .
dcaba79
 
Posts: 4
Joined: Mon Nov 23, 2015 12:19 pm

Re: IF THEN ELSE commands

by chivracq on Thu Mar 17, 2016 7:15 pm

dcaba79 wrote:I will give this a try, got a idea of what you are saying, I will create something with eval to activate only the lines need according to the results .

Well, good luck and post your final Script once you've got it working or if you get stuck somewhere and I will probably be able to improve/tune it a bit... Well, if you mention your FCI, I won't follow up otherwise... Read my Sig...

Because I see that you've tried to comply a bit with "FCIM", but your FCI is still not complete and actually a bit unclear:
Browser is firefox
OS Windows 10

VERSION BUILD=8940826 RECORDER=FX

You don't mention your FF Version at all... :roll:
Your Script mentions v8.9.4 but I would actually be a bit surprised if you are really (still) using this Version as it is already a few months old and only works/worked until FF42, while we are currently at FF44/45... :?
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6477
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: IF THEN ELSE commands

by dcaba79 on Fri Mar 18, 2016 8:26 am

Thank you chivracq I figured it out had to do a bit of working modifing the script as javascipt is a language I'm not to familiar with this is my final code , i would like a way not to have to write p on the csv that if the C OR N isn't found do the last part of the script


'CANCELS
SET !VAR1 EVAL("if (\"{{!COL13}}\" == \"C\") {var x=1}; x;")
TAG POS={{!VAR1}} TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbCancel CONTENT=YES
TAG POS={{!VAR1}} TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_ddlCancelReasons CONTENT=%55

'NO SHOWS
SET !VAR2 EVAL("if (\"{{!COL13}}\" == \"N\") {var x=1}; x;")
TAG POS={{!VAR2}} TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbCancel CONTENT=YES
TAG POS={{!VAR2}} TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_ddlCancelReasons CONTENT=%1

'PICKUPS
SET !VAR3 EVAL("if (\"{{!COL13}}\" == \"P\") {var x=1}; x;")
TAG POS={{!VAR3}} TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbConfirm CONTENT=YES
TAG POS={{!VAR3}} TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtVehicleID CONTENT={{!COL6}}
TAG POS={{!VAR3}} TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtDriverID CONTENT={{!COL7}}
dcaba79
 
Posts: 4
Joined: Mon Nov 23, 2015 12:19 pm

Re: IF THEN ELSE commands

by chivracq on Fri Mar 18, 2016 8:50 am

dcaba79 wrote:Thank you chivracq I figured it out had to do a bit of working modifing the script as javascipt is a language I'm not to familiar with this is my final code , i would like a way not to have to write p on the csv that if the C OR N isn't found do the last part of the script


Code: Select all
'CANCELS
SET !VAR1 EVAL("if (\"{{!COL13}}\" == \"C\") {var x=1}; x;")
TAG POS={{!VAR1}} TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbCancel CONTENT=YES
TAG POS={{!VAR1}} TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_ddlCancelReasons CONTENT=%55

'NO SHOWS
SET !VAR2 EVAL("if (\"{{!COL13}}\" == \"N\") {var x=1}; x;")
TAG POS={{!VAR2}} TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbCancel CONTENT=YES
TAG POS={{!VAR2}} TYPE=SELECT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_ddlCancelReasons CONTENT=%1

'PICKUPS
SET !VAR3 EVAL("if (\"{{!COL13}}\" == \"P\") {var x=1}; x;")
TAG POS={{!VAR3}} TYPE=INPUT:CHECKBOX FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_cbConfirm CONTENT=YES
TAG POS={{!VAR3}} TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtVehicleID CONTENT={{!COL6}}
TAG POS={{!VAR3}} TYPE=INPUT:TEXT FORM=ID:aspnetForm ATTR=ID:ctl00_cphMainContent_rpAttestation_ctl{{!COL14}}_txtDriverID CONTENT={{!COL7}}

Code: Select all
FIREFOX 44.0.2
OS Windows 10
IMACRO VERSION BUILD=8961227

OK, you've edited/completed your FCI and it looks more logical indeed...

Your Script looks good, I'm impressed...! And you are nearly the first one to understand my Technique a bit directly...!

About your 'P' Condition, simply use:
Code: Select all
SET !VAR3 EVAL("if ('{{!COL13}}' != ('C'||'N')) {var x=1}; x;")
(Not tested...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6477
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: IF THEN ELSE commands

by dcaba79 on Mon Mar 21, 2016 1:23 pm

Yeah the your script idea briliant , thank you for you help .
Took some trial and error. I found it helpful to run it without the SET !ERRORIGNORE to see where it was failing once everything was correct I activated the SET !ERRORIGNORE and we are we at no. It works flawless. Thanks again
dcaba79
 
Posts: 4
Joined: Mon Nov 23, 2015 12:19 pm

Re: IF THEN ELSE commands

by chivracq on Mon Mar 21, 2016 4:50 pm

dcaba79 wrote:Yeah the your script idea briliant , thank you for you help .
Took some trial and error. I found it helpful to run it without the SET !ERRORIGNORE to see where it was failing once everything was correct I activated the SET !ERRORIGNORE and we are we at no. It works flawless. Thanks again

Yep, always deactivate '!ERRORIGNORE' and use 'PROMPT' when trying to debug your Script, I've got some 'PROMPT''S that are 3 Screens large, well the Statement, not the Content of the Prompt, ah-ah...!

Yep, don't worry, all my Ideas are "Brilliant", that's why I'm answering so many Threads, but it's just a Question of a little bit of Creativity, and I have the Feeling you are picking up very quickly and are soon going to help me... 8) :D
(Meant as a Compliment, as I said, I think it's the first time in 3 years that I've been a bit active on this Forum and sometimes giving Solutions using my Method, which is not the "Standard' Method, even if TechSup copied my Main Thread where I explained it recently to some 'Howto' Sub-Forum which is finally some kind of Recognition..., that sbd understands it so quickly..., so...,well, glad to welcome you...!) :D

>>>

Oh..., but you should post your Final Script, to finish your Thread a bit neatly, for other Users to see what was the original Script and what is the Final (better working) Script... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6477
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Scripting and Command Line Interface

Who is online

Users browsing this forum: No registered users and 5 guests

-->