Need help with scripting looped actions

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++.
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.

Need help with scripting looped actions

by aegorhum on Mon Jul 09, 2018 3:23 pm

Hello,

First time poster, please be gentle. I'm new to iMacros and I'm starting to wonder if this was the right tool for what this project turned into. Some information:

    VERSION BUILD=12.0.501.6698
    Browser is IE 11
    OS is Windows 10 x64, 1709

Everything so far has worked pretty well. Steep learning curve, but I've picked most of it up in the last month or two. So, The Issue:

My input file (csv) contains unique identifiers for packages that we're forwarding. The system that we're working in requires the user to
    click on a unique shipment identifier
    submit to proceed to the next page
      for each parcel on the shipment
      input packing cost
      update location
      click "yes" radio button
      click submit
      foreach_parcel_screen.png
      Click yes and enter information for each parcel (in numerical order)

        to finalize the shipment
        click submit on a total parcel verification page
        shpt_verification_screen.png
        Shipment Verification

        input transportation mode and freight cost and submit to complete the process for that shipment
        final_screen.png
        Final steps to complete the process


Getting through one of these won't be a problem, it's stringing them together that I don't understand how to do. Each shipment can have 1-40+ parcels, so I can't assign a static number of loops, but...I don't know how to handle the variance. It's worth mentioning that once this process begins it must be completed or it has to be redone.

The users are having to do up to 200 of these shipments a day, so I'm really hoping for some wisdom and insight from the community. Screenshot examples attached, please let me know if I need to clarify anything or provide more data. Thanks!
Last edited by aegorhum on Tue Jul 10, 2018 8:04 am, edited 1 time in total.
aegorhum
 
Posts: 7
Joined: Mon Jul 09, 2018 1:31 pm

Re: Is this even possible with iMacros?

by chivracq on Mon Jul 09, 2018 3:45 pm

aegorhum wrote:Hello,

First time poster, please be gentle. I'm new to iMacros and I'm starting to wonder if this was the right tool for what this project turned into. Some information:

    Code: Select all
    VERSION BUILD=12.0.501.6698
    Browser is IE 11
    OS is Windows 10 x64, 1709

Everything so far has worked pretty well. Steep learning curve, but I've picked most of it up in the last month or two. So, The Issue:

My input file (csv) contains unique identifiers for packages that we're forwarding. The system that we're working in requires the user to
    click on a unique shipment identifier
    submit to proceed to the next page
      for each parcel on the shipment
      input packing cost
      update location
      click "yes" radio button
      click submit
      foreach_parcel_screen.png

        to finalize the shipment
        click submit on a total parcel verification page
        shpt_verification_screen.png

        input transportation mode and freight cost and submit to complete the process for that shipment
        final_screen.png


Getting through one of these won't be a problem, it's stringing them together that I don't understand how to do. Each shipment can have 1-40+ parcels, so I can't assign a static number of loops, but...I don't know how to handle the variance. It's worth mentioning that once this process begins it must be completed or it has to be redone.

The users are having to do up to 200 of these shipments a day, so I'm really hoping for some wisdom and insight from the community. Screenshot examples attached, please let me know if I need to clarify anything or provide more data. Thanks!

Hum..., Okay..., I'll be gentle...!! :mrgreen:

FCI mentioned, perfect...! :D
(But you should still read my Sig... :idea: )

Your Script has apparently/probably nothing to do with the 'Scripting Interface', you don't sound like you are launching your Script from a '.VBS' or 'C#' Script, or you would already know how to implement your Script... :?
Correct Sub-Forum was the 'General' one (where your Thread will probably be moved to), but no need to duplicate now....

One "Blocking" Thing in your Thread that you'll need to "improve" for me to answer it currently, is your Thread Title which is not Descriptive about its Content, try searching the Forum for similar Threads with "Is+this+even+possible+with+iMacros?" as Search Keywords..., hum..., good luck...! :idea:
But OK, if that's your "real" Qt, then the Answer is "Yes"...! :D
(Good, that was an easy one, ah-ah...!, and 1 more happy Customer...!, ... of course...! :roll: , everything is possible with iMacros...! 8) )
Last edited by chivracq on Tue Jul 10, 2018 9:21 am, edited 1 time in total.
- (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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Is this even possible with iMacros?

by aegorhum on Tue Jul 10, 2018 8:03 am

Hi Chivracq,

I am launching my macros from .VBS scripts currently, the issue is that I don't know how to do what I've described. I haven't written any macros for this (or created the .VBS wrappers) yet because I don't know how many macros are needed or how to loop through them correctly. If I were to break it down, I believe it would be three macros:
Macro 1
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
'URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/MfgProOnTheWeb.html
FRAME NAME=FS_main
TAG POS=1 TYPE=A ATTR=TXT:CODXW079
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:submit-jumpto

Macro 2
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
'URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/MfgProOnTheWeb.html
FRAME NAME=FS_main
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC1 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC1 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK1
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC2 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC2 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK2
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC3 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC3 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK3
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC4 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC4 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK4
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto

Macro 3
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
'URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/MfgProOnTheWeb.html
FRAME NAME=FS_main
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=SELECT ATTR=NAME:Type_transport CONTENT=%TRUCK
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:FreightCost CONTENT=0


This doesn't use a loop (because I don't know how to loop through it correctly) and I didn't hit the final submit button (because the customer hasn't given us access to the test environment). I call macros to log in to the site and browse to the correct menu from .VBS because the HTML of the site's menu structure is..."wonky". Either way, that method works for me and it makes modifications easy (e.g. when the customer provides more permissions and the menu structure changes).

Each DOC# can have multiple DO#s, each with multiple parcels. These parcels are listed in numerical order (DO#1/par#1, DO#2/par#1, DO#1/par#2, DO#2/par#2) instead of the DO#s being listed in numerical order. One of the challenges is that each parcel must be submitted in DO#/parcel# order. So, the submit order for the above example must be DO#1/par#1, DO#1/par#2, DO#2/par#1, DO#2/par#2.

Since the number of DOs and parcels per DOC# is not consistent, I don't think looping line by line is the way to go.

If I were do try to put this into PowerShell, I think it would look something like this (though it's still not right since there's duplicate DOC#s and the pack_cost would be erratic)
Code: Select all
$csv = import-csv c:\input_file
$DOC = $csv.docn
foreach ($COD in $DOC) {
    $DOns = $csv.don | where-object {($csv).docn -like $COD}
    $Cost = $csv.freight_cost | where-object {($csv).docn -like $COD}
    $Loc = $csv.new_loc | where-object {($csv).docn -like $COD}
    TAG POS=1 TYPE=A ATTR=TXT:$DOC
    TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:submit-jumpto
    foreach ($DOn in $DOns) {
        $Parns = $csv.parceln | where-object {($csv).don -like $DOn}
        foreach ($Parn in $Parns) {
            $PCost = $csv.pack_cost | where-object {($csv).parceln -like $Parn}
            TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC$Parn CONTENT=0
            TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC$Parn CONTENT=$Loc
            TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK$Parn
        }
    }
    TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
    TAG POS=1 TYPE=SELECT ATTR=NAME:Type_transport CONTENT=%TRUCK
    TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:FreightCost CONTENT=$Cost
}
Attachments
csv_input.png
Example input data
aegorhum
 
Posts: 7
Joined: Mon Jul 09, 2018 1:31 pm

Re: Need help with scripting looped actions

by chivracq on Tue Jul 10, 2018 11:32 am

aegorhum wrote:Hi Chivracq,

I am launching my macros from .VBS scripts currently, the issue is that I don't know how to do what I've described. I haven't written any macros for this (or created the .VBS wrappers) yet because I don't know how many macros are needed or how to loop through them correctly. If I were to break it down, I believe it would be three macros:
Macro 1
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
'URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/MfgProOnTheWeb.html
FRAME NAME=FS_main
TAG POS=1 TYPE=A ATTR=TXT:CODXW079
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:submit-jumpto

Macro 2
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
'URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/MfgProOnTheWeb.html
FRAME NAME=FS_main
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC1 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC1 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK1
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC2 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC2 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK2
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC3 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC3 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK3
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC4 CONTENT=0
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC4 CONTENT=E1L1
TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK4
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto

Macro 3
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
'SET !PLAYBACKDELAY 0.00
'URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/MfgProOnTheWeb.html
FRAME NAME=FS_main
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=SELECT ATTR=NAME:Type_transport CONTENT=%TRUCK
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:FreightCost CONTENT=0


This doesn't use a loop (because I don't know how to loop through it correctly) and I didn't hit the final submit button (because the customer hasn't given us access to the test environment). I call macros to log in to the site and browse to the correct menu from .VBS because the HTML of the site's menu structure is..."wonky". Either way, that method works for me and it makes modifications easy (e.g. when the customer provides more permissions and the menu structure changes).

Each DOC# can have multiple DO#s, each with multiple parcels. These parcels are listed in numerical order (DO#1/par#1, DO#2/par#1, DO#1/par#2, DO#2/par#2) instead of the DO#s being listed in numerical order. One of the challenges is that each parcel must be submitted in DO#/parcel# order. So, the submit order for the above example must be DO#1/par#1, DO#1/par#2, DO#2/par#1, DO#2/par#2.

Since the number of DOs and parcels per DOC# is not consistent, I don't think looping line by line is the way to go.

If I were do try to put this into PowerShell, I think it would look something like this (though it's still not right since there's duplicate DOC#s and the pack_cost would be erratic)
Code: Select all
$csv = import-csv c:\input_file
$DOC = $csv.docn
foreach ($COD in $DOC) {
    $DOns = $csv.don | where-object {($csv).docn -like $COD}
    $Cost = $csv.freight_cost | where-object {($csv).docn -like $COD}
    $Loc = $csv.new_loc | where-object {($csv).docn -like $COD}
    TAG POS=1 TYPE=A ATTR=TXT:$DOC
    TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:submit-jumpto
    foreach ($DOn in $DOns) {
        $Parns = $csv.parceln | where-object {($csv).don -like $DOn}
        foreach ($Parn in $Parns) {
            $PCost = $csv.pack_cost | where-object {($csv).parceln -like $Parn}
            TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:PAR_PAC$Parn CONTENT=0
            TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC$Parn CONTENT=$Loc
            TAG POS=2 TYPE=INPUT:RADIO ATTR=NAME:STOCK$Parn
        }
    }
    TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto
    TAG POS=1 TYPE=SELECT ATTR=NAME:Type_transport CONTENT=%TRUCK
    TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:FreightCost CONTENT=$Cost
}

OK, good...!, Thread Title is now Descriptive, even if the "Need help" part is always "useless", but OK, we can talk...! :D
(You edited your Thread Title after posting your last Reply, so that new Title didn't get taken over as Title for that Post, but OK, never mind...)

Hum..., and OK, you do use the Scripting Interface actually (=> correct Sub-Forum then), with a '.VBS' Script, yeah then, that was "worth" mentioning in your OP, ah-ah...! And that means you are a "Professional", even better...!, as "Professionals" tend to "understand" my "Explanations" and "Solutions"/"(Creative) Ideas for Implementation" usually more easily than "Script Kiddies", ah-ah...! :wink:

But, OK, this is going to be some "Interesting" Thread after all, ah-ah...! :D
(Hum, and "funnily" enough, some Friend of mine works for 'slb', ah-ah...! :P )

Yeah, well, everything you want is indeed not very-very complicated, it could even be done with just 1 single Macro in pure '.iim' (I only use pure '.iim' for myself anyway), even if you'll have a bit more "Control" from a main '.VBS' Script...

Like you've already found out, you'll then need to "split" the complete Workflow of your whole Process into several Sub-Processes (with each a separate Sub-(on-the-fly)-'.iim' Macro and you'll need to "organize" them from your main '.vbs' Script logically according to their Dependencies and Nested Level, with or without Looping...
You could maybe already have a look at the following Thread, with complete Script Example(s), with several Sub-Macros controlled from a main '.vbs' Script as well, even if in that Thread, all Sub-Macros run a bit "linearly" with some simple 'IF' Condition, until the Final Script posted where the Workflow gets a bit a "Nested Levels" with several 'IF/ELSE' Conditions (but no Looping). But you'll find many Examples with (Nested) Looping in '.js' Scripts on the Forum, if you need Examples..., hum..., like in this recent Post for example where I had posted a few Links to such Threads... But OK, the '.vbs' Thread:
- Identify Wich Step Has Failed
(Hum, nearly surprised I didn't "bash" that User for the ugly Typo in their Thread Title, I normally don't answer Threads until the Thread Title is Descriptive and doesn't contain any Typos/Spelling Mistakes anymore... :oops: )

For your (Nested) Loops, think about using 'while' or 'until' Loops instead of 'for' Loops for the parts where you don't know how many times you might need to loop a specific Sub-Macro, for the 'DO#'-Parcels for example, even if you could still use a 'for' Loop, as the "3" (Parcels) is already displayed on the Page and could be extracted and passed to the main '.vbs' to be reused for the 'for' Loop..., while a 'while' or 'until' Loop will, at the beginning or the end of the Macro, check if there is a new/next 'DOC' or 'DO' to handle or if the Loop can be aborted to go to the next "Step"... :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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help with scripting looped actions

by aegorhum on Tue Jul 10, 2018 3:22 pm

chivracq wrote:OK, good...!, Thread Title is now Descriptive, even if the "Need help" part is always "useless", but OK, we can talk...! :D
(You edited your Thread Title after posting your last Reply, so that new Title didn't get taken over as Title for that Post, but OK, never mind...)

Please accept my deepest regret at failing to adhere to your strict thread-titling schema
chivracq wrote:Hum..., and OK, you do use the Scripting Interface actually (=> correct Sub-Forum then), with a '.VBS' Script, yeah then, that was "worth" mentioning in your OP,

Indeed, I do use the scripting interface and I did choose the correct sub-forum. I did not find mentioning my use of .vbs wrappers helpful as I didn't want give off the impression that I'm tied to .vbs.
chivracq wrote:ah-ah...! And that means you are a "Professional", even better...!, as "Professionals" tend to "understand" my "Explanations" and "Solutions"/"(Creative) Ideas for Implementation" usually more easily than "Script Kiddies", ah-ah...! :wink:

IT Professional, yes. Still very new to .vbs, .js, .iim, etc., though.
chivracq wrote:But, OK, this is going to be some "Interesting" Thread after all, ah-ah...! :D
(Hum, and "funnily" enough, some Friend of mine works for 'slb', ah-ah...! :P )

And I have some friends from NL :D It's a small world!
chivracq wrote:Yeah, well, everything you want is indeed not very-very complicated, it could even be done with just 1 single Macro in pure '.iim' (I only use pure '.iim' for myself anyway), even if you'll have a bit more "Control" from a main '.VBS' Script...

Like you've already found out, you'll then need to "split" the complete Workflow of your whole Process into several Sub-Processes (with each a separate Sub-(on-the-fly)-'.iim' Macro and you'll need to "organize" them from your main '.vbs' Script logically according to their Dependencies and Nested Level, with or without Looping...
You could maybe already have a look at the following Thread, with complete Script Example(s), with several Sub-Macros controlled from a main '.vbs' Script as well, even if in that Thread, all Sub-Macros run a bit "linearly" with some simple 'IF' Condition, until the Final Script posted where the Workflow gets a bit a "Nested Levels" with several 'IF/ELSE' Conditions (but no Looping). But you'll find many Examples with (Nested) Looping in '.js' Scripts on the Forum, if you need Examples..., hum..., like in this recent Post for example where I had posted a few Links to such Threads... But OK, the '.vbs' Thread:
- Identify Wich Step Has Failed

I do understand the need for nesting and sub-processes. I don't understand at all how this can be done with a single .iim, but I'm new and this world is full of wonders.

I don't find those examples helpful because I can't wrap my head around how they are similar to my issue. Again, this is probably because I'm new to these languages. It doesn't make it any easier to see the correlation.
chivracq wrote:(Hum, nearly surprised I didn't "bash" that User for the ugly Typo in their Thread Title, I normally don't answer Threads until the Thread Title is Descriptive and doesn't contain any Typos/Spelling Mistakes anymore... :oops: )

This is disturbing. I get that you're a knowledgeable person and you're (assumption) helping others out of the kindness of your heart and not for compensation. We're all human, though. Mistakes will be made and, more to the point, not everyone has read your comprehensive list of rules, laws, bylaws and do's & don'ts of the forum...Additionally, it seems like English isn't the primary language of many posters, including yours. You make several typos and grammatical errors...guess I shouldn't respond until they're fixed?
chivracq wrote:For your (Nested) Loops, think about using 'while' or 'until' Loops instead of 'for' Loops for the parts where you don't know how many times you might need to loop a specific Sub-Macro, for the 'DO#'-Parcels for example, even if you could still use a 'for' Loop, as the "3" (Parcels) is already displayed on the Page and could be extracted and passed to the main '.vbs' to be reused for the 'for' Loop..., while a 'while' or 'until' Loop will, at the beginning or the end of the Macro, check if there is a new/next 'DOC' or 'DO' to handle or if the Loop can be aborted to go to the next "Step"... :idea:

Maybe this is the crux of the issue. I understand that there needs to be a way to "step into" and "step out of" the loops, but I don't understand how to do that. Maybe something like this:
Code: Select all
Dim myCSVPath
Dim myCSVFile
Dim oConnection
Dim oRecordSet
Dim myDOCvar
Dim Counter
Dim LineNumber

myCSVPath = "C:\imacros\"
 
myCSVFile = myCSVPath&"input_data.csv"

Set oConnection = createobject("adodb.connection")
SEt oRecordSet = createobject("adodb.recordset")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & sCSVFileLocation & ";Extended Properties=""text;HDR=yes;FMT=Delimited"""
oRecordSet.open "SELECT * FROM " & myCSVFile ,oConnection

myDOCvar = oRecordSet.Fields.Item(0).value

I'm going to stop there because I don't think oRecordSet is the correct vbscript (method/statement/command) for this task. Just not sure how to define that variable, do specific actions for lines where {{!col1}} is = to the variable, step back to do the last step and then redefine the variable to start the process over....wish there was better support/documentation for PowerShell!
aegorhum
 
Posts: 7
Joined: Mon Jul 09, 2018 1:31 pm

Re: Need help with scripting looped actions

by chivracq on Tue Jul 10, 2018 8:00 pm

OK, trying to reply in Quote-Blocks..., I keep my own Quotes for "Relevancy" because in mini-Blocks... :oops:

aegorhum wrote:
chivracq wrote:OK, good...!, Thread Title is now Descriptive, even if the "Need help" part is always "useless", but OK, we can talk...! :D
(You edited your Thread Title after posting your last Reply, so that new Title didn't get taken over as Title for that Post, but OK, never mind...)

Please accept my deepest regret at failing to adhere to your strict thread-titling schema
chivracq wrote:Hum..., and OK, you do use the Scripting Interface actually (=> correct Sub-Forum then), with a '.VBS' Script, yeah then, that was "worth" mentioning in your OP,

Indeed, I do use the scripting interface and I did choose the correct sub-forum. I did not find mentioning my use of .vbs wrappers helpful as I didn't want give off the impression that I'm tied to .vbs.
chivracq wrote:ah-ah...! And that means you are a "Professional", even better...!, as "Professionals" tend to "understand" my "Explanations" and "Solutions"/"(Creative) Ideas for Implementation" usually more easily than "Script Kiddies", ah-ah...! :wink:

IT Professional, yes. Still very new to .vbs, .js, .iim, etc., though.
chivracq wrote:But, OK, this is going to be some "Interesting" Thread after all, ah-ah...! :D
(Hum, and "funnily" enough, some Friend of mine works for 'slb', ah-ah...! :P )

And I have some friends from NL :D It's a small world!

Yeah, OK-OK...
I did not find mentioning my use of .vbs wrappers helpful as I didn't want give off the impression that I'm tied to .vbs.

=> Hum, then 1 single Script in pure '.iim' is maybe an Option for you, then, ah-ah...! :idea:

aegorhum wrote:
chivracq wrote:Yeah, well, everything you want is indeed not very-very complicated, it could even be done with just 1 single Macro in pure '.iim' (I only use pure '.iim' for myself anyway), even if you'll have a bit more "Control" from a main '.VBS' Script...

Like you've already found out, you'll then need to "split" the complete Workflow of your whole Process into several Sub-Processes (with each a separate Sub-(on-the-fly)-'.iim' Macro and you'll need to "organize" them from your main '.vbs' Script logically according to their Dependencies and Nested Level, with or without Looping...
You could maybe already have a look at the following Thread, with complete Script Example(s), with several Sub-Macros controlled from a main '.vbs' Script as well, even if in that Thread, all Sub-Macros run a bit "linearly" with some simple 'IF' Condition, until the Final Script posted where the Workflow gets a bit a "Nested Levels" with several 'IF/ELSE' Conditions (but no Looping). But you'll find many Examples with (Nested) Looping in '.js' Scripts on the Forum, if you need Examples..., hum..., like in this recent Post for example where I had posted a few Links to such Threads... But OK, the '.vbs' Thread:
- Identify Wich Step Has Failed

I do understand the need for nesting and sub-processes. I don't understand at all how this can be done with a single .iim, but I'm new and this world is full of wonders.

I don't find those examples helpful because I can't wrap my head around how they are similar to my issue. Again, this is probably because I'm new to these languages. It doesn't make it any easier to see the correlation.

I do 20x times more "complex" things than you want/need in this Thread in pure '.iim', well I was already 10 years ago when I just had discovered iMacros, after 3 hours... (1.5x only then... :wink: ). OK, requires a little bit of "Creative Thinking" indeed...
I've always used only the Free Add-on for FF, supporting '.js' Scripts... which I never needed as I was always able to find a way to do my Coding in pure '.iim'..., I have a "Solution" in pure '.iim' for everything that "needs" to be "Conditional" or repeated... (Well "repeated" is simple...! => Means "Looping"...!, or sometimes hard-coding 40 times checking a 'YES' for some RB, ah-ah...! :idea: , yeah, I know, not really OO, but iMacros does "the Job" in 0.5 sec... (Hum, except in v10 for FF, oops!, needs 600-800ms now per "Not-Found-Click"...))

The "Principle" is always the same with any Prog-Lang, simply see any "Sub-Macro" as a Function that you control with all the "Power" of your Prog-Lang for any Conditional Logic, IF/Looping/etc... (You can declare Macros as Funcs btw...)

aegorhum wrote:
chivracq wrote:(Hum, nearly surprised I didn't "bash" that User for the ugly Typo in their Thread Title, I normally don't answer Threads until the Thread Title is Descriptive and doesn't contain any Typos/Spelling Mistakes anymore... :oops: )

This is disturbing. I get that you're a knowledgeable person and you're (assumption) helping others out of the kindness of your heart and not for compensation. We're all human, though. Mistakes will be made and, more to the point, not everyone has read your comprehensive list of rules, laws, bylaws and do's & don'ts of the forum...Additionally, it seems like English isn't the primary language of many posters, including yours. You make several typos and grammatical errors...guess I shouldn't respond until they're fixed?

Yeah well, I'm talking about a Thread Title with 64 Chars max, containing max 10 Words that will be used by other Users as Search Keywords to search the Forum for similar Threads..., I type Replies with 1000 Chars or maybe 1000 Words(?), I try to type as correctly as I can, and to correct my own Typos or Grammatical Mistakes afterwards if I can spot them, Eng is indeed not my Native Language, like more than 80% of Users on the Forum, I'll be happy to correct any Spelling/Grammar Mistakes I will probably have made if you can point me to them... :wink: )

Hum, and "Assumptions" are always "healthy"..., hum "Doubts" are actually healthier I would think..., but any both easy to check for me or for any User on the Forum... :idea:

aegorhum wrote:
chivracq wrote:For your (Nested) Loops, think about using 'while' or 'until' Loops instead of 'for' Loops for the parts where you don't know how many times you might need to loop a specific Sub-Macro, for the 'DO#'-Parcels for example, even if you could still use a 'for' Loop, as the "3" (Parcels) is already displayed on the Page and could be extracted and passed to the main '.vbs' to be reused for the 'for' Loop..., while a 'while' or 'until' Loop will, at the beginning or the end of the Macro, check if there is a new/next 'DOC' or 'DO' to handle or if the Loop can be aborted to go to the next "Step"... :idea:

Maybe this is the crux of the issue. I understand that there needs to be a way to "step into" and "step out of" the loops, but I don't understand how to do that. Maybe something like this:
Code: Select all
Dim myCSVPath
Dim myCSVFile
Dim oConnection
Dim oRecordSet
Dim myDOCvar
Dim Counter
Dim LineNumber

myCSVPath = "C:\imacros\"
 
myCSVFile = myCSVPath&"input_data.csv"

Set oConnection = createobject("adodb.connection")
SEt oRecordSet = createobject("adodb.recordset")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & sCSVFileLocation & ";Extended Properties=""text;HDR=yes;FMT=Delimited"""
oRecordSet.open "SELECT * FROM " & myCSVFile ,oConnection

myDOCvar = oRecordSet.Fields.Item(0).value

I'm going to stop there because I don't think oRecordSet is the correct vbscript (method/statement/command) for this task. Just not sure how to define that variable, do specific actions for lines where {{!col1}} is = to the variable, step back to do the last step and then redefine the variable to start the process over....wish there was better support/documentation for PowerShell!

Hum, for this last Quote, I'll need to think a wee bit, a bit tired now already, oops!, already 05h for me :oops: , I'll check again and reply tomorrow after some sleep I guess... 8)
- (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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help with scripting looped actions

by chivracq on Tue Jul 10, 2018 11:22 pm

chivracq wrote:
aegorhum wrote:
chivracq wrote:For your (Nested) Loops, think about using 'while' or 'until' Loops instead of 'for' Loops for the parts where you don't know how many times you might need to loop a specific Sub-Macro, for the 'DO#'-Parcels for example, even if you could still use a 'for' Loop, as the "3" (Parcels) is already displayed on the Page and could be extracted and passed to the main '.vbs' to be reused for the 'for' Loop..., while a 'while' or 'until' Loop will, at the beginning or the end of the Macro, check if there is a new/next 'DOC' or 'DO' to handle or if the Loop can be aborted to go to the next "Step"... :idea:

Maybe this is the crux of the issue. I understand that there needs to be a way to "step into" and "step out of" the loops, but I don't understand how to do that. Maybe something like this:
Code: Select all
Dim myCSVPath
Dim myCSVFile
Dim oConnection
Dim oRecordSet
Dim myDOCvar
Dim Counter
Dim LineNumber

myCSVPath = "C:\imacros\"
 
myCSVFile = myCSVPath&"input_data.csv"

Set oConnection = createobject("adodb.connection")
SEt oRecordSet = createobject("adodb.recordset")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & sCSVFileLocation & ";Extended Properties=""text;HDR=yes;FMT=Delimited"""
oRecordSet.open "SELECT * FROM " & myCSVFile ,oConnection

myDOCvar = oRecordSet.Fields.Item(0).value

I'm going to stop there because I don't think oRecordSet is the correct vbscript (method/statement/command) for this task. Just not sure how to define that variable, do specific actions for lines where {{!col1}} is = to the variable, step back to do the last step and then redefine the variable to start the process over....wish there was better support/documentation for PowerShell!

Hum, for this last Quote, I'll need to think a wee bit, a bit tired now already, oops!, already 05h for me :oops: , I'll check again and reply tomorrow after some sleep I guess... 8)

Hum, didn't go to bed actually (yet...)..., so I still had a chance to have a look at your Script... :oops:

Can't really help you with 'vbs'/'PowerShell', but I've seen "easier" Methods to access Excel Cells from a '.vbs' Script, check SOF maybe for that I would say, if you want to "do it" directly from '.vbs'... :idea:

But iMacros has a very straightforward Mechanism as well for accessing/retrieving Cells from a '.CSV' DataSource, you only need to keep track in your main '.vbs' about the Row_Nb in the '.CSV' (=> '!DATASOURCE_LINE' for iMacros, usually based on '!LOOP' in pure '.iim', but you need to handle the Looping yourself from a '.js' or '.vbs' Script (with 'iimSet()')), and '{{!COLn}}' for the n_Cell in that Row.

And from an (on-the-fly) Macro, you simply need to increment the '!DATASOURCE_LINE' with "1" (hard-coded) to already retrieve the same Cell (= same Col) that you want (to retrieve/check) for the next Row in the same Macro to already check if it exists or is the same/different like/from your current Row (with 'EVAL()') or simply pass it to the main '.vbs' (using the 'EXTRACT' + 'iimGetExtract()' Mechanism) where you can do the Check also... (Hum, recommended actually, using 'EVAL()' inside an on-the-fly Macro in some '.js' or '.vbs' Script is "Not Best Practice" in my Opinion anyway, ah-ah...!)

>>>

And the "Golden Advice" I can give you to learn iMacros as quickly as possible, is... euh...: Don't like my "Style" at all, but follow a bit my "Instructions"/Suggs, and you'll see, within one Qt/Thread, maybe 2 max, you won't need any Help anymore at all from the Forum (and from me of course, ah-ah...!), believe me, it works...! :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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help with scripting looped actions

by chivracq on Wed Jul 11, 2018 8:30 am

Hum, I was looking for some Thread I remembered from a few months ago where the User was using some "elegant"/interesting Mechanism to access (and manipulate) the Excel Cells directly from their main '.vbs' or '.vba' Script (without using the '.iim' ['!DATASOURCE' + '!DATASOURCE_LINE' + '!COLn'] Mechanism) but I don't seem to be able to locate that Thread... :x

But the same or a similar Mechanism is demonstrated I see in some '.vba' Demo-Macro as well...:
- Excel VBA Example Code
- (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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help with scripting looped actions

by aegorhum on Wed Jul 11, 2018 3:07 pm

chivracq wrote:Hum, I was looking for some Thread I remembered from a few months ago where the User was using some "elegant"/interesting Mechanism to access (and manipulate) the Excel Cells directly from their main '.vbs' or '.vba' Script (without using the '.iim' ['!DATASOURCE' + '!DATASOURCE_LINE' + '!COLn'] Mechanism) but I don't seem to be able to locate that Thread... :x

But the same or a similar Mechanism is demonstrated I see in some '.vba' Demo-Macro as well...:
- Excel VBA Example Code

Apologies for the lack of response today, it's been hectic on my end. I'm still reading through and will respond tomorrow. Thanks for all of your help thus far!
aegorhum
 
Posts: 7
Joined: Mon Jul 09, 2018 1:31 pm

Re: Need help with scripting looped actions

by chivracq on Wed Jul 11, 2018 3:14 pm

aegorhum wrote:Apologies for the lack of response today, it's been hectic on my end. I'm still reading through and will respond tomorrow. Thanks for all of your help thus far!

Yeah-yeah, don't worry, no Pb..., it's Summertime anyway and nice Weather, I'm not always "available" either... (+ Time Difference... (I'm located in NL (Europe)). 8)
And I guess you need to "digest" a bit the "Stuff" I give you each time, ah-ah...! :wink:
- (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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help with scripting looped actions

by aegorhum on Tue Jul 17, 2018 10:29 am

chivracq wrote:Yeah-yeah, don't worry, no Pb..., it's Summertime anyway and nice Weather, I'm not always "available" either... (+ Time Difference... (I'm located in NL (Europe)). 8)
And I guess you need to "digest" a bit the "Stuff" I give you each time, ah-ah...! :wink:
I suppose the weather is nice but it is HOT!

chivracq wrote:Can't really help you with 'vbs'/'PowerShell', but I've seen "easier" Methods to access Excel Cells from a '.vbs' Script, check SOF maybe for that I would say, if you want to "do it" directly from '.vbs'... :idea:

Not sure what SOF is :?
chivracq wrote:But iMacros has a very straightforward Mechanism as well for accessing/retrieving Cells from a '.CSV' DataSource, you only need to keep track in your main '.vbs' about the Row_Nb in the '.CSV' (=> '!DATASOURCE_LINE' for iMacros, usually based on '!LOOP' in pure '.iim', but you need to handle the Looping yourself from a '.js' or '.vbs' Script (with 'iimSet()')), and '{{!COLn}}' for the n_Cell in that Row.

See, I don't see it as being easy to work with when you *must* keep up with your cells. I know this is partially due to my inexperience with the syntax and commands, but it's not object oriented so it doesn't "feel" like the logic-driver of a solution.
chivracq wrote:And from an (on-the-fly) Macro, you simply need to increment the '!DATASOURCE_LINE' with "1" (hard-coded) to already retrieve the same Cell (= same Col) that you want (to retrieve/check) for the next Row in the same Macro to already check if it exists or is the same/different like/from your current Row (with 'EVAL()') or simply pass it to the main '.vbs' (using the 'EXTRACT' + 'iimGetExtract()' Mechanism) where you can do the Check also... (Hum, recommended actually, using 'EVAL()' inside an on-the-fly Macro in some '.js' or '.vbs' Script is "Not Best Practice" in my Opinion anyway, ah-ah...!)

I almost resorted to using EXTRACT, but I found it easier to keep up with my rows and variables in VBS than iMacros.
chivracq wrote:And the "Golden Advice" I can give you to learn iMacros as quickly as possible, is... euh...: Don't like my "Style" at all, but follow a bit my "Instructions"/Suggs, and you'll see, within one Qt/Thread, maybe 2 max, you won't need any Help anymore at all from the Forum (and from me of course, ah-ah...!), believe me, it works...! :idea:

Yeah, it's difficult to get in to. I understand it a lot more now that I know it wasn't designed to be the logic of a solution and have used it accordingly. It's a great tool and I'm considering finding out how deep the rabbit hole goes.

I'll post my scripts in another reply in order to keep it neat and organized. Thanks again for your help! You pushed me in the right direction, the rest came down to R&D and T&E.
aegorhum
 
Posts: 7
Joined: Mon Jul 09, 2018 1:31 pm

Re: Need help with scripting looped actions

by aegorhum on Tue Jul 17, 2018 11:00 am

This solution is broken down into one VBScript that provides the logic for three iMacros that carry out simple tasks on the website. I decided to do everything I could with VBScript because it, in my opinion, creates a stable platform that can be reused in other projects and solutions. I also find that it's easier and produces less "code" than keeping up with data inside the macros. Could be a personal preference, but it's one that I'll hold until shown otherwise.

Anyway, on to the solution!

VBS
Code: Select all
Option Explicit
'On Error Resume Next

'Define file name and path for VBS
    Dim vbsCSV, vbsCSVloc
    vbsCSVloc = "C:\users\user\documents\imacros\datasources\"
    vbsCSV = vbsCSVloc & "docconf.csv"
'

'Check if file exists
    If Not CreateObject("Scripting.FileSystemObject").FileExists(vbsCSV) Then
        Msgbox "The input file doesn't exist.  Please add the file " & vbsCSV
        Wscript.Quit
    End If
'

'Dim Definitions
    Dim iim1, i, iret
    Dim mDOC, cDOC, cCost, cMoT, cLoc
    Dim pLine, oRst, oConnection
'

'Commands used to open the CSV file and select all of the records
    set oConnection = CreateObject("ADODB.Connection")
    oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & vbsCSVloc & ";" & _
    "Extended Properties=""text;HDR=yes;FMT=Delimited"""
    SEt oRst = oConnection.Execute( "SELECT * FROM docconf1.csv")
'

'Initial iMacros setup
    'find current folder for iMacros
    Dim myname, mypath
    myname = WScript.ScriptFullName
    mypath = Left(myname, InstrRev(myname, "\"))

    set iim1 = CreateObject ("imacros")

    iret = iim1.iimOpen("")
   
    'Log in to SLB Gold
    iret = iim1.iimPlay(mypath & "slb_login.iim")
    'Browse to correct menu
    iret = iim1.iimPlay(mypath & "slb_menu_doc_confirmation.iim")
'

'Set positional arguments
    oRst.MoveFirst
'

'Quit when EoF
   'If oRst.EOF Then
    '   Msgbox "No records found"
    '   Wscript.Quit
    'End If
'

Do Until oRst.EOF
    mDOC = Trim(oRst.Fields.Item(0).value)
    cDOC = Trim(oRst.Fields.Item(0).value)
    cCost = Trim(oRst.Fields.Item(2).value)
    cMoT = Trim(oRst.Fields.Item(3).value)
    'iMacros script #1 - Click on DOC & click submit
        iret = iim1.iimSet("iDOC", cstr(cDOC))
        iret = iim1.iimPlay(mypath & "PRO_SLB_doc_conf_pt1.iim")
    '

    Do while mDOC = cDOC
        'iMacros script #2 - Change location, click yes & click submit
            iret = iim1.iimSet("iDOC", cstr(cDOC))
            iret = iim1.iimPlay(mypath & "PRO_SLB_doc_conf_pt2.iim")
        '
        oRst.MoveNext
        mDOC = Trim(oRst.Fields.Item(0).value)
    Loop

    'Then do...

    'iMacros script #3 - Click submit, select MoT, enter cost & enter AWB
        iret = iim1.iimSet("iDOC", cstr(cDOC))
        iret = iim1.iimSet("iCost", cstr(cCost))
        iret = iim1.iimSet("iMoT", cstr(cMoT))
        iret = iim1.iimPlay(mypath & "PRO_SLB_doc_conf_pt3.iim")
    '
Loop

Pardon my blocking...I use VS Code for all script writing and this keeps it nice and neat. The script uses two variables to define your csv path and filename, tells you if the file doesn't exist, creates an ADO DB connection to the csv file and "imports" the data as the recordset.
The "Initial iMacros Setup" creates the necessary variables and then calls two macros to 1.) log in to the website and 2.) browse to the correct menu.
After this, the script will do these actions until EOF is reached.

Do Until
All variables are defined and a variable is passed to the first iMacro.
_pt1.iim
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
FRAME NAME=FS_main
TAG POS=1 TYPE=A ATTR=TXT:{{iDOC}}
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:submit-jumpto


Do while mDOC = cDOC
Variable is passed to second iMacro. After _pt2.iim runs, the script advances to the next record, sets the mDOC variable and then starts over. If mDOC is still = to cDOC then the loop continues, otherwise it skips to the next block.
_pt2.iim
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
FRAME NAME=FS_main
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC1 CONTENT=PSF-US
EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>CENTER:nth-of-type(2)>TABLE>TBODY>TR:nth-of-type(2)>TD:nth-of-type(6)>DIV>INPUT:nth-of-type(2)" BUTTON=0
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto


The last bit passes three variables into the third iMacro and then loops back to the beginning.
_pt3.iim
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
FRAME NAME="FS_main"
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:EXPEDITION ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=SELECT FORM=NAME:EXPEDITION ATTR=NAME:Type_transport CONTENT=%{{iMoT}}
TAB T=2
URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/platform/expedition/w1exp0120.w?DONbr={{iDOC}}&Type_trans={{iMoT}}
TAG POS=1 TYPE=SELECT FORM=NAME:COURRIER ATTR=NAME:CARRIER CONTENT=%Pentagon
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:COURRIER ATTR=NAME:AWB CONTENT={{iDOC}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:COURRIER ATTR=NAME:submit-jumpto
TAB T=1
FRAME NAME="FS_main"
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:EXPEDITION ATTR=NAME:FreightCost CONTENT={{iCost}}
ONDIALOG POS=1 BUTTON=YES
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:EXPEDITION ATTR=NAME:jumpto


The key element is the two different DOC variables, mDOC & cDOC. The master variable (mDOC) advances to the DOC# in the next row every time _pt2.iim is played and is then checked against the current variable (cDOC) at the beginning of the loop. Since it's a "do while loop", it continues until the logic test is false (when mDOC is not = to cDOC).

Please, use the script if it helps you or make comments/suggestions if there's areas to improve. I'm new to both of these languages so, as much as I want to help others, I'm still learning.
aegorhum
 
Posts: 7
Joined: Mon Jul 09, 2018 1:31 pm

Re: Need help with scripting looped actions

by chivracq on Tue Jul 17, 2018 2:40 pm

aegorhum wrote:
chivracq wrote:Yeah-yeah, don't worry, no Pb..., it's Summertime anyway and nice Weather, I'm not always "available" either... (+ Time Difference... (I'm located in NL (Europe)). 8)
And I guess you need to "digest" a bit the "Stuff" I give you each time, ah-ah...! :wink:
I suppose the weather is nice but it is HOT!

chivracq wrote:Can't really help you with 'vbs'/'PowerShell', but I've seen "easier" Methods to access Excel Cells from a '.vbs' Script, check SOF maybe for that I would say, if you want to "do it" directly from '.vbs'... :idea:

Not sure what SOF is :?
chivracq wrote:But iMacros has a very straightforward Mechanism as well for accessing/retrieving Cells from a '.CSV' DataSource, you only need to keep track in your main '.vbs' about the Row_Nb in the '.CSV' (=> '!DATASOURCE_LINE' for iMacros, usually based on '!LOOP' in pure '.iim', but you need to handle the Looping yourself from a '.js' or '.vbs' Script (with 'iimSet()')), and '{{!COLn}}' for the n_Cell in that Row.

See, I don't see it as being easy to work with when you *must* keep up with your cells. I know this is partially due to my inexperience with the syntax and commands, but it's not object oriented so it doesn't "feel" like the logic-driver of a solution.
chivracq wrote:And from an (on-the-fly) Macro, you simply need to increment the '!DATASOURCE_LINE' with "1" (hard-coded) to already retrieve the same Cell (= same Col) that you want (to retrieve/check) for the next Row in the same Macro to already check if it exists or is the same/different like/from your current Row (with 'EVAL()') or simply pass it to the main '.vbs' (using the 'EXTRACT' + 'iimGetExtract()' Mechanism) where you can do the Check also... (Hum, recommended actually, using 'EVAL()' inside an on-the-fly Macro in some '.js' or '.vbs' Script is "Not Best Practice" in my Opinion anyway, ah-ah...!)

I almost resorted to using EXTRACT, but I found it easier to keep up with my rows and variables in VBS than iMacros.
chivracq wrote:And the "Golden Advice" I can give you to learn iMacros as quickly as possible, is... euh...: Don't like my "Style" at all, but follow a bit my "Instructions"/Suggs, and you'll see, within one Qt/Thread, maybe 2 max, you won't need any Help anymore at all from the Forum (and from me of course, ah-ah...!), believe me, it works...! :idea:

Yeah, it's difficult to get in to. I understand it a lot more now that I know it wasn't designed to be the logic of a solution and have used it accordingly. It's a great tool and I'm considering finding out how deep the rabbit hole goes.

I'll post my scripts in another reply in order to keep it neat and organized. Thanks again for your help! You pushed me in the right direction, the rest came down to R&D and T&E.

Hum, real "Pleasure" to read your nice analytically structured Posts...! :D , the "Reason" why I prefer "professionals", I guess, ah-ah...! :wink:
And hum, I'll be a bit "lazier" and will reply "in block", oops... :oops:

SOF = The 'Stackoverflow' Forum...! :wink:
There are a few Threads about iMacros there, even if the "Quality" there (for iMacros Threads) is usually not very-very High (my own Opinion, of course....!), at least since a few months already that some Advanced User seems to have stopped answering iMacros Threads, replaced by 2 other semi-Advanced Users who now "fake"-answer all iMacros Threads to only redirect all Users towards the 'Kantu' Browser, ah-ah...! Politics and Commercial Interests I guess, ah-ah...! :shock:
(And I refuse to answer Threads on SOF (anymore) because I don't like their "stupid" Reputation System, and I can't ask a User to mention their FCI without getting all my other Answers/Solutions downvoted if they don't like it, ah-ah...! :roll: )
=> Low Quality for iMacros, but it is (still) the "Reference" for '.vbs'/'.vba', JS, C++, C#..., and many other Prog-Languages, even in combination with iMacros as it requires the iMacros 'Scripting Interface' to use those Languages with iMacros (except for '.js' Scripts) and the iMacros Users using the Scripting Interface usually have direct Access to TechSupport and such Threads never reach the Forum, so there is not much "Expertise" about '.vbs'/'C#'/etc on the Forum where it's more Users using the Free Add-ons (like me) helping other Users... (Hum, and I don't even use '.js' Scripts myself...)

But yep..., good to "do" as much as you can from '.vbs' actually... That's a "wise Choice", I would think... 8)
You are a bit in the "Luxury Position" that you are using '.vbs', you then have access to the "Full Power" of '.vbs' to handle/control '.CSV'/'.XLS' Files which is indeed much more powerful than the few iMacros Commands.
And iMacros only lets you use (2D) '.CSV' Files (as DataSource or for Saveas), where you can access "Cells" only one by one using their 'Row+Col' Coordinates (and you can't even use a Var (natively) for the '!COLn' Horizontal Coordinate!, even if there are a few "Tricks" to do so..., even in pure '.iim', I can retrieve/manipulate the Data Row (Range) by Row or Col (Range) by Col, or even the Full '.CSV' at once using a few "Tricks", and hum..., since a few weeks/months, I've actually even started to move towards "my own" '.CSV' Format where I save all the Data in just one Cell, then I have more "Control" on 2D/3D Arrays that I regularly need for my own Scripts), while from '.vbs', you can use 3D DataSources (=> '.xls' Files for example with more than 1 Sheet if you want...).

Hum, I think I'll post as well a 2nd Reply corresponding to your 2nd Reply with your Script... :wink:
Last edited by chivracq on Tue Jul 17, 2018 7:28 pm, edited 1 time in total.
- (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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help with scripting looped actions

by chivracq on Tue Jul 17, 2018 3:51 pm

aegorhum wrote:This solution is broken down into one VBScript that provides the logic for three iMacros that carry out simple tasks on the website. I decided to do everything I could with VBScript because it, in my opinion, creates a stable platform that can be reused in other projects and solutions. I also find that it's easier and produces less "code" than keeping up with data inside the macros. Could be a personal preference, but it's one that I'll hold until shown otherwise.

Anyway, on to the solution!

VBS
Code: Select all
Option Explicit
'On Error Resume Next

'Define file name and path for VBS
    Dim vbsCSV, vbsCSVloc
    vbsCSVloc = "C:\users\user\documents\imacros\datasources\"
    vbsCSV = vbsCSVloc & "docconf.csv"
'

'Check if file exists
    If Not CreateObject("Scripting.FileSystemObject").FileExists(vbsCSV) Then
        Msgbox "The input file doesn't exist.  Please add the file " & vbsCSV
        Wscript.Quit
    End If
'

'Dim Definitions
    Dim iim1, i, iret
    Dim mDOC, cDOC, cCost, cMoT, cLoc
    Dim pLine, oRst, oConnection
'

'Commands used to open the CSV file and select all of the records
    set oConnection = CreateObject("ADODB.Connection")
    oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & vbsCSVloc & ";" & _
    "Extended Properties=""text;HDR=yes;FMT=Delimited"""
    SEt oRst = oConnection.Execute( "SELECT * FROM docconf1.csv")
'

'Initial iMacros setup
    'find current folder for iMacros
    Dim myname, mypath
    myname = WScript.ScriptFullName
    mypath = Left(myname, InstrRev(myname, "\"))

    set iim1 = CreateObject ("imacros")

    iret = iim1.iimOpen("")
   
    'Log in to SLB Gold
    iret = iim1.iimPlay(mypath & "slb_login.iim")
    'Browse to correct menu
    iret = iim1.iimPlay(mypath & "slb_menu_doc_confirmation.iim")
'

'Set positional arguments
    oRst.MoveFirst
'

'Quit when EoF
   'If oRst.EOF Then
    '   Msgbox "No records found"
    '   Wscript.Quit
    'End If
'

Do Until oRst.EOF
    mDOC = Trim(oRst.Fields.Item(0).value)
    cDOC = Trim(oRst.Fields.Item(0).value)
    cCost = Trim(oRst.Fields.Item(2).value)
    cMoT = Trim(oRst.Fields.Item(3).value)
    'iMacros script #1 - Click on DOC & click submit
        iret = iim1.iimSet("iDOC", cstr(cDOC))
        iret = iim1.iimPlay(mypath & "PRO_SLB_doc_conf_pt1.iim")
    '

    Do while mDOC = cDOC
        'iMacros script #2 - Change location, click yes & click submit
            iret = iim1.iimSet("iDOC", cstr(cDOC))
            iret = iim1.iimPlay(mypath & "PRO_SLB_doc_conf_pt2.iim")
        '
        oRst.MoveNext
        mDOC = Trim(oRst.Fields.Item(0).value)
    Loop

    'Then do...

    'iMacros script #3 - Click submit, select MoT, enter cost & enter AWB
        iret = iim1.iimSet("iDOC", cstr(cDOC))
        iret = iim1.iimSet("iCost", cstr(cCost))
        iret = iim1.iimSet("iMoT", cstr(cMoT))
        iret = iim1.iimPlay(mypath & "PRO_SLB_doc_conf_pt3.iim")
    '
Loop

Pardon my blocking...I use VS Code for all script writing and this keeps it nice and neat. The script uses two variables to define your csv path and filename, tells you if the file doesn't exist, creates an ADO DB connection to the csv file and "imports" the data as the recordset.
The "Initial iMacros Setup" creates the necessary variables and then calls two macros to 1.) log in to the website and 2.) browse to the correct menu.
After this, the script will do these actions until EOF is reached.

Do Until
All variables are defined and a variable is passed to the first iMacro.
_pt1.iim
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
FRAME NAME=FS_main
TAG POS=1 TYPE=A ATTR=TXT:{{iDOC}}
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:submit-jumpto


Do while mDOC = cDOC
Variable is passed to second iMacro. After _pt2.iim runs, the script advances to the next record, sets the mDOC variable and then starts over. If mDOC is still = to cDOC then the loop continues, otherwise it skips to the next block.
_pt2.iim
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
FRAME NAME=FS_main
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:NEWLOC1 CONTENT=PSF-US
EVENT TYPE=CLICK SELECTOR="HTML>BODY>FORM>CENTER:nth-of-type(2)>TABLE>TBODY>TR:nth-of-type(2)>TD:nth-of-type(6)>DIV>INPUT:nth-of-type(2)" BUTTON=0
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:submit-jumpto


The last bit passes three variables into the third iMacro and then loops back to the beginning.
_pt3.iim
Code: Select all
VERSION BUILD=12.0.501.6698
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
FRAME NAME="FS_main"
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:EXPEDITION ATTR=NAME:submit-jumpto
TAG POS=1 TYPE=SELECT FORM=NAME:EXPEDITION ATTR=NAME:Type_transport CONTENT=%{{iMoT}}
TAB T=2
URL GOTO=https://www.gold.oilfield.slb.com/cgi-bin/wspd_cgi.sh/WService=gold/platform/expedition/w1exp0120.w?DONbr={{iDOC}}&Type_trans={{iMoT}}
TAG POS=1 TYPE=SELECT FORM=NAME:COURRIER ATTR=NAME:CARRIER CONTENT=%Pentagon
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:COURRIER ATTR=NAME:AWB CONTENT={{iDOC}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:COURRIER ATTR=NAME:submit-jumpto
TAB T=1
FRAME NAME="FS_main"
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:EXPEDITION ATTR=NAME:FreightCost CONTENT={{iCost}}
ONDIALOG POS=1 BUTTON=YES
TAG POS=1 TYPE=INPUT:BUTTON FORM=NAME:EXPEDITION ATTR=NAME:jumpto


The key element is the two different DOC variables, mDOC & cDOC. The master variable (mDOC) advances to the DOC# in the next row every time _pt2.iim is played and is then checked against the current variable (cDOC) at the beginning of the loop. Since it's a "do while loop", it continues until the logic test is false (when mDOC is not = to cDOC).

Please, use the script if it helps you or make comments/suggestions if there's areas to improve. I'm new to both of these languages so, as much as I want to help others, I'm still learning.

Very-very nice...!, a Big Thanks for the Forum Community for sharing your Script, like I already mentioned, there are not that many '.vbs' Script Examples on the Forum, so this one will probably be very useful... :D
And it is very nicely written, with Comments included, and very "safely" coded, ah-ah...! 8)

Nice to see the 'while' Loop nested inside the 'Until' Loop btw... 8)

=> Hum, '.vbs' is not Case Sensitive, I reckon..., a bit surprised by the "while" (no Capital) and "Until" (with Capital), and "set" + "SEt"...

Your '.vbs' Script looks very neat to me, from what I can follow, ah-ah...! Impressive for sbd who's "new to both of these languages", ah-ah...! 8)

You will maybe want to add (can be done later...) some 'iimDisplay()' if you want to visually "follow" what your Script is doing, and maybe some Logging if you are going to run this Script regularly if you ever need to pull any "Statistics"/Reporting and/or Error Troubleshooting in case anything ever goes "wrong", but that's just an "Idea"...

And for the '.iim' parts, you may want to "tune" a bit the Speed by shortening the different '!TIMEOUT_xxx' Settings that you've left at their Default Values, as you've enabled '!ERRORIGNORE'...

But OK, was nice "guiding" you a bit in this Thread for your "first Steps", you learn "nearly" too quickly, ah-ah...!, I will nearly be surprised if you ever need some Help again on the Forum, ah-ah...! :wink:
- (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: 7714
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to Command Line and Scripting Interface

Who is online

Users browsing this forum: No registered users and 3 guests

-->