If Statement Using VBA Info

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
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
senor pengwin
Posts: 41
Joined: Thu Aug 17, 2017 10:33 pm

If Statement Using VBA Info

Post by senor pengwin » Sat Jul 14, 2018 7:40 am

I am using:
VERSION BUILD=12.0.501.6698
IMacros Browser
Windows 7 64 Bit

I am oversimplifying what I am trying to do because I just need help with this one part.
Basically I have a VBA that is activating an IMacro but it is also going to calculate a number, 1-5. I just want the action below to run the amount of times that is calculated in the VBA

This is the line I need to run in IMacros:

Code: Select all

TAG POS=1 TYPE=TD ATTR=ID:calBack
I need something that can say something like:

Code: Select all

IF {{VBANumber}} = 1 THEN
TAG POS=1 TYPE=TD ATTR=ID:calBack

ELSE IF {{VBANumber}} = 2 THEN
TAG POS=1 TYPE=TD ATTR=ID:calBack
TAG POS=1 TYPE=TD ATTR=ID:calBack
etc....



Thanks
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Sat Jul 14, 2018 4:22 pm

senor pengwin wrote:I am using:

Code: Select all

VERSION BUILD=12.0.501.6698
IMacros Browser
Windows 7 64 Bit
I am oversimplifying what I am trying to do because I just need help with this one part.
Basically I have a VBA that is activating an IMacro but it is also going to calculate a number, 1-5. I just want the action below to run the amount of times that is calculated in the VBA

This is the line I need to run in IMacros:

Code: Select all

TAG POS=1 TYPE=TD ATTR=ID:calBack
I need something that can say something like:

Code: Select all

IF {{VBANumber}} = 1 THEN
TAG POS=1 TYPE=TD ATTR=ID:calBack

ELSE IF {{VBANumber}} = 2 THEN
TAG POS=1 TYPE=TD ATTR=ID:calBack
TAG POS=1 TYPE=TD ATTR=ID:calBack
etc....

Thanks
Yep..., simply use a 'For Next' Loop like in the Demo Macro... :idea:
... Ah-ah...!, ... which is indeed the same Example like in the Thread where you've posted in Reply... 8)

And if your 'VBANumber' comes from some (previous) (on-the-fly) '.iim' Macro, you pass it from that Macro to the main '.vba' Script using the '!EXTRACT' + iimGetExtract()' Mechanism to reuse it as a Var for the Loop instead of the hard-coded "2" in the Example...
- (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...
senor pengwin
Posts: 41
Joined: Thu Aug 17, 2017 10:33 pm

Re: If Statement Using VBA Info

Post by senor pengwin » Sat Jul 14, 2018 10:10 pm

chivracq wrote: Yep..., simply use a 'For Next' Loop like in the Demo Macro... :idea:

Yes I was thinking about this, so basically just create a new IMacro's with just that line and do a for loop on it when i want it to run? That line is included in a much larger IMacros file. I don't want to run the whole IMacro's file that many times, just that one line in the IMacros file.

Basically what I am doing is going to a website and downloading a report based on an input date in the excel file. The problem is with the website you can only select a day in the current month. If I want to get a date from a previous month I need to click a button to scroll through the months, so I am calculating how many months away the input date is from todays date, and that is how many times i want to press the button, then continue with downloading the report, saving, etc.

Thanks
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Sun Jul 15, 2018 1:28 am

senor pengwin wrote:
chivracq wrote: Yep..., simply use a 'For Next' Loop like in the Demo Macro... :idea:

Yes I was thinking about this, so basically just create a new IMacro's with just that line and do a for loop on it when i want it to run? That line is included in a much larger IMacros file. I don't want to run the whole IMacro's file that many times, just that one line in the IMacros file.

Basically what I am doing is going to a website and downloading a report based on an input date in the excel file. The problem is with the website you can only select a day in the current month. If I want to get a date from a previous month I need to click a button to scroll through the months, so I am calculating how many months away the input date is from todays date, and that is how many times i want to press the button, then continue with downloading the report, saving, etc.

Thanks
Yeah, but I don't know how your "much larger IMacros file" looks like (correct Spelling is "iMacros" btw...! :wink: ), nice to try to "oversimplify" things, but that usually doesn't really work with me, the more Info the better (for me...!), don't worry, I see "through" Code/Music/whatever using Colours and I can focus on any part I decide...

But yep I would think, simply split your big Macro into 2 parts, one with the one-line 'calBack' mini-Macro (hum, some Programmer can't speak proper English I would think, ah-ah...!, if "calBack' is meant for "callBack", dunno what "calBack" could mean otherwise...!), and the other part for the rest that doesn't need to be repeated [2-5] times...

But everything should be very-very straightforward from the Info you provided, I honestly don't see any Difficulty at all..., unless I'm missing stg..., maybe from your "oversimplifying"... :idea:
- (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...
senor pengwin
Posts: 41
Joined: Thu Aug 17, 2017 10:33 pm

Re: If Statement Using VBA Info

Post by senor pengwin » Sun Jul 15, 2018 2:46 am

chivracq wrote:
senor pengwin wrote:
chivracq wrote: Yep..., simply use a 'For Next' Loop like in the Demo Macro... :idea:

Yes I was thinking about this, so basically just create a new IMacro's with just that line and do a for loop on it when i want it to run? That line is included in a much larger IMacros file. I don't want to run the whole IMacro's file that many times, just that one line in the IMacros file.

Basically what I am doing is going to a website and downloading a report based on an input date in the excel file. The problem is with the website you can only select a day in the current month. If I want to get a date from a previous month I need to click a button to scroll through the months, so I am calculating how many months away the input date is from todays date, and that is how many times i want to press the button, then continue with downloading the report, saving, etc.

Thanks
Yeah, but I don't know how your "much larger IMacros file" looks like (correct Spelling is "iMacros" btw...! :wink: ), nice to try to "oversimplify" things, but that usually doesn't really work with me, the more Info the better (for me...!), don't worry, I see "through" Code/Music/whatever using Colours and I can focus on any part I decide...

But yep I would think, simply split your big Macro into 2 parts, one with the one-line 'calBack' mini-Macro (hum, some Programmer can't speak proper English I would think, ah-ah...!, if "calBack' is meant for "callBack", dunno what "calBack" could mean otherwise...!), and the other part for the rest that doesn't need to be repeated [2-5] times...

But everything should be very-very straightforward from the Info you provided, I honestly don't see any Difficulty at all..., unless I'm missing stg..., maybe from your "oversimplifying"... :idea:
No need to make it complicated, I get what you're saying. I just wanted to do a for loop in IMacros and only create one file, not have Part 1, variable IMacro, Part 2. But I will work around, thanks
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Sun Jul 15, 2018 3:21 am

senor pengwin wrote:No need to make it complicated, I get what you're saying. I just wanted to do a for loop in IMacros and only create one file, not have Part 1, variable IMacro, Part 2. But I will work around, thanks
"No need to make it complicated", not sure if you are referring to me or yourself, but I couldn't agree more... :D

Hum, still can't spell "iMacros" correctly => ["IMacros"]... Sic...! :roll:

But OK, "work around" and post your Final Script and/or if you get stuck, but including some simple 'for' Loop in a Script shouldn't be very difficult, I would think... :wink:

Arrgghhh...!, but reading your Reply again..., you don't need to create "Part 1" + "Part 2", 'Part 2' is the rest of your undisclosed "large Script", it's only 'Part 1' (your one-line 'calBack' Statement) that you are going to loop...
Oh hum, unless your 'VBA_whatever' Var that you need for the Loop needs to be extracted from some Web-Page first..., but then, tja...!, that's the way iMacros works, ah-ah...! Every Click-Click-Click, Data Extraction, Save, Web-Interaction, Form Filling, etc..., can be done in iMacros, but every time you want to include some Conditional Logic, you need to go back to your main '.vba' Script for that..., or you do like me everything in pure '.iim' in just one single '.iim' Script..., and you don't need any Scripting Interface with '.vba' or whatever...

[I must be missing stg because there is no Difficulty at all in what you want if I understood a bit correctly, especially if you are using iMacros from '.vbs'/'.vba', you already know how to program a bit I would think... :? ]
Last edited by chivracq on Sun Jul 15, 2018 5:22 pm, edited 5 times in total.
- (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...
senor pengwin
Posts: 41
Joined: Thu Aug 17, 2017 10:33 pm

Re: If Statement Using VBA Info

Post by senor pengwin » Sun Jul 15, 2018 3:43 am

chivracq wrote:
senor pengwin wrote: Hum, still can't spell "iMacros" correctly => "IMacros"... :roll:
Hum, :?: not really sure what you mean, maybe our screens are displaying something different but I capitalized the I in my post, still trying to figure out how this is relevant to anything I have said though. Thanks for the help.

Image
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Sun Jul 15, 2018 3:55 am

senor pengwin wrote:
chivracq wrote:
senor pengwin wrote: Hum, still can't spell "iMacros" correctly => "IMacros"... :roll:
Hum, :?: not really sure what you mean, maybe our screens are displaying something different but I capitalized the I in my post, still trying to figure out how this is relevant to anything I have said though. Thanks for the help.

Image
Yeah well, never mind, "iMacros" is spelt without a Capital 'I', simple...! The Capital is on the 'M'... :roll:

I edited my previous Reply btw in the time you had already replied..., I was looking for some Thread to link to, took a mini-while and you had already posted your Reply...

But good luck anyway, I don't want to go into some "Argument" with you, simply post your Final Script once you've found the Solution... 8)

And hum, nearly surprised I could see your Quote as a Screenshot, I've already blocked 80% of that stupid 'photobucket' Site... Hum, well the Site maybe is not "stupid" but their Users are, always using heavy '.gif' Files >100Kb, and even more often >1Mb in their Sig on most Forums I use...
Screenshots on the iMacros Forum should be uploaded directly to the Forum anyway, not using any external Image Hosting Site that will go dark or commercial like all of them... or get blocked by "Normal" Users like me... :roll:
Last edited by chivracq on Sun Jul 15, 2018 4:10 am, edited 1 time in total.
- (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...
senor pengwin
Posts: 41
Joined: Thu Aug 17, 2017 10:33 pm

Re: If Statement Using VBA Info

Post by senor pengwin » Sun Jul 15, 2018 4:04 am

chivracq wrote: Yeah well, never mind, "iMacros" is spelt without a Capital 'I', simple...! The Capital is on the 'M'... :roll:

I edited my previous Reply btw in the time you had already replied..., I was looking for some Thread to link to, took a mini-while and you had already posted your Reply...

But good luck anyway, I don't want to go into some "Argument" with you, simply post your Final Script once you've found the Solution... 8)
Good Sir, I appreciate your input but no need to patronize, we all require "editing" at times. I believe we all know what we are talking about here. I never mentioned anything about any "difficulties" I was just trying to see if there was a way to complete this task in one "iMacros" file rather than three.

I have great respect for your all posts but we are not all on your "iMacros" level. :roll:
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Sun Jul 15, 2018 4:18 am

senor pengwin wrote:Good Sir, I appreciate your input but no need to patronize, we all require "editing" at times. I believe we all know what we are talking about here. I never mentioned anything about any "difficulties" I was just trying to see if there was a way to complete this task in one "iMacros" file rather than three.

I have great respect for your all posts but we are not all on your "iMacros" level. :roll:
Yeah well, I actually do all my iMacros Coding in pure '.iim' because I don't have the Knowledge/Skills to use '.vbs' or '.js' Scripts ah-ah...! Too "High Level" for me, that's why I try to keep it "simple" in pure '.iim'... :wink:

Hum, very good...! "iMacros" spelt correctly... :D , I knew you could do it, ah-ah...! :wink:
- (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...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Thu Jul 19, 2018 12:25 am

Hum..., I was checking your Thread to see if you had followed up and posted your Script since last "Exchange", 4 days ago..., but nope...! :cry:

Maybe that can help, here is a Link to some other Thread from the last few days, where some (exemplary!) User, completely new to iMacros (and '.vbs'/'.vba'), I think they started/discovered both Tools/Languages about 1 week ago [you have 1 year Advance already, ah-ah...! [Oops, I'm "patronizing" again, sorry... :oops: ]], posted their Final Script, with a very nice Example of some 'While' Loop nested inside an 'Until' Loop... :D
(Not a 'For' Loop, like I think you needed, but the Principle will be the same...)
- Re: Need help with scripting looped actions
Hope this helps... 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...
senor pengwin
Posts: 41
Joined: Thu Aug 17, 2017 10:33 pm

Re: If Statement Using VBA Info

Post by senor pengwin » Thu Jul 19, 2018 5:36 am

chivracq wrote:Hum..., I was checking your Thread to see if you had followed up and posted your Script since last "Exchange", 4 days ago..., but nope...! :cry:

Maybe that can help, here is a Link to some other Thread from the last few days, where some (exemplary!) User, completely new to iMacros (and '.vbs'/'.vba'), I think they started/discovered both Tools/Languages about 1 week ago [you have 1 year Advance already, ah-ah...! [Oops, I'm "patronizing" again, sorry... :oops: ]], posted their Final Script, with a very nice Example of some 'While' Loop nested inside an 'Until' Loop... :D
(Not a 'For' Loop, like I think you needed, but the Principle will be the same...)
- Re: Need help with scripting looped actions
Hope this helps... 8)
No problem, thanks I will look into this in more detail when I get a little more time. I ended up doing this in VBA:

Code: Select all

    'Declare Variables
    Dim DLBook As Workbook
    Dim RefSheet As Worksheet
    Dim SelectedState, DaySelector As String
    Dim iim1, iret, SelectedDate, x

    'Set Worksheet
    Set DLBook = ActiveWorkbook
    Set RefSheet = DLBook.Sheets("Ref")
    
    'Set values to variables
    SelectedState = RefSheet.Range("D11").Value
    SelectedDate = RefSheet.Range("D7").Value
    DaySelector = (Date - 1) - SelectedDate

    If SelectedState = "Florida" Then
        SelectedState = "FL (27)"
    ElseIf SelectedState = "DFW" Then
        SelectedState = "TX (32)"

    'Open iMacros Browser
    Set iim1 = CreateObject("imacros")
    iret = iim1.iimInit
        
        'Do Part 1
        iret = iim1.iimSet("selectedstate", SelectedState)
        iret = iim1.iimPlay("Sales Reports\XformityByDay - Part1")
        
        'Condition on this iMacro, only play if "DaySelector" variable is > 0 and run it that many times
        If DaySelector > 0 Then
        For x = 1 To DaySelector
        iret = iim1.iimPlay("Sales Reports\XformityByDay - PrevDay")
        Next x
        End If
        
        'Run final portion of iMacro to save report
        iret = iim1.iimPlay("Sales Reports\XformityByDay - Part2")

        If iret < 0 Then
            MsgBox iim1.iimGetLastError() 'Message if error
        End If
        iret = iim1.iimExit
Then the VBA will take the saved report file and distribute it to 4 different Excel files that use that report.

EDIT: I read the other thread, makes sense. I have about 5 years working with Visual Basic so my understanding is much greater there. I had started messing with iMacros about a year ago but my trial ran out and the free version limited my number of lines so I gave up on it. I just recently started picking it up again the past 2 weeks as my work has approved me to purchase a license. Using VBA and iMacros is a very powerful combination indeed.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: If Statement Using VBA Info

Post by chivracq » Thu Jul 19, 2018 11:27 pm

senor pengwin wrote:No problem, thanks I will look into this in more detail when I get a little more time. I ended up doing this in VBA:

Code: Select all

    'Declare Variables
    Dim DLBook As Workbook
    Dim RefSheet As Worksheet
    Dim SelectedState, DaySelector As String
    Dim iim1, iret, SelectedDate, x

    'Set Worksheet
    Set DLBook = ActiveWorkbook
    Set RefSheet = DLBook.Sheets("Ref")
    
    'Set values to variables
    SelectedState = RefSheet.Range("D11").Value
    SelectedDate = RefSheet.Range("D7").Value
    DaySelector = (Date - 1) - SelectedDate

    If SelectedState = "Florida" Then
        SelectedState = "FL (27)"
    ElseIf SelectedState = "DFW" Then
        SelectedState = "TX (32)"

    'Open iMacros Browser
    Set iim1 = CreateObject("imacros")
    iret = iim1.iimInit
        
        'Do Part 1
        iret = iim1.iimSet("selectedstate", SelectedState)
        iret = iim1.iimPlay("Sales Reports\XformityByDay - Part1")
        
        'Condition on this iMacro, only play if "DaySelector" variable is > 0 and run it that many times
        If DaySelector > 0 Then
        For x = 1 To DaySelector
        iret = iim1.iimPlay("Sales Reports\XformityByDay - PrevDay")
        Next x
        End If
        
        'Run final portion of iMacro to save report
        iret = iim1.iimPlay("Sales Reports\XformityByDay - Part2")

        If iret < 0 Then
            MsgBox iim1.iimGetLastError() 'Message if error
        End If
        iret = iim1.iimExit
Then the VBA will take the saved report file and distribute it to 4 different Excel files that use that report.

EDIT: I read the other thread, makes sense. I have about 5 years working with Visual Basic so my understanding is much greater there. I had started messing with iMacros about a year ago but my trial ran out and the free version limited my number of lines so I gave up on it. I just recently started picking it up again the past 2 weeks as my work has approved me to purchase a license. Using VBA and iMacros is a very powerful combination indeed.
Perfect..., thanks for sharing...! :D

Sounds easier from '.vba' I would think, like you do, instead of from '.vbs' like the other User, then you can access directly the Data from your '.xls' Sheet(s), and you don't need to connect through OLEDB or whatever like they do... 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