Need Help Writing Extracted Data from Web Site to ReportFile

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
MGuyM
Junior Coder
Posts: 36
Joined: Tue Jul 24, 2007 12:59 am

Need Help Writing Extracted Data from Web Site to ReportFile

Post by MGuyM » Wed Jul 02, 2008 2:55 am

Good Evening.

I discovered a bug with writing data to a ReportFile that my Script extracts data from a Web Site using the IE_EXTRACT Tag. The following Script runs Fine through MS, but when I use MS to Create an EXE and Run it, then the Data written to the Log File is incorrect. I'm going to Post the Full Code and Log Files here for complete Explanation.

I am using v10.1.16 of MS and v2.04/2.02 of WebRecorder to Create the following Script.

Code: Select all

// Generated by MacroScript WebRecorder 2.04
// Recorded on Tuesday, July 1, 2008, at 07:00 PM

//Load IEAuto.DLL Library
LibLoad>%Sys_Dir%\IEAuto.DLL,hie

//Load VBScript
VBSTart
VBEND

//Move the mouse cursor out of harm's way to avoid causing mouseover events to interrupt
MouseMove>0,0
Let>delay=1
Let>comma=,
Let>ReportFile=%CWD%\Output.TXT

//Delete Log File if Exists
IfFileExists>%ReportFile%
  DeleteFile>%ReportFile%
ENDIF

//Record TimeStamp in Report File
TimeStamp>%ReportFile%,Macro Started

//Launch IE
IE_Create>0,IE[0]
IE_Show>IE[0],1,r

IE_Navigate>%IE[0]%,http://www.mjtnet.com/usergroup/?c=2,r
IE_Wait>%IE[0]%,r
Wait>delay

Let>X=1

//Start Loop
Label>Start

### Extract Tag for Technical / Scripting Forum ###
//Modify buffer size if required ...
Let>A70_SIZE=4098
IE_ExtractTag>%IE[0]%,,A,70,0,A70,r

//Trim Data to be Written to File
VBEVAL>Trim("%A70%"),strReportValue

Let>strData=%X%
ConCat>strData,Comma
ConCat>strData,%strReportValue%
ConCat>strData,Comma
ConCat>strData,%A70%
TimeStamp>%ReportFile%,%strData%

Let>X=X+1
IF>X<5>%IE[0]%,r

//Close Log File
TimeStamp>%ReportFile%,Macro Finished

//Release Library
LibFree>hIE

Label>end_script
Now here is the OutPut File when run through MS:

Code: Select all

19:40:21:578 - Macro Started
19:40:34:000 - 1,Technical / Scripting,Technical / Scripting
19:40:34:015 - 2,Technical / Scripting,Technical / Scripting
19:40:34:015 - 3,Technical / Scripting,Technical / Scripting
19:40:34:031 - 4,Technical / Scripting,Technical / Scripting
19:40:34:062 - Macro Finished
And here is the Same Output File when run as a Compiled EXE:

Code: Select all

19:44:22:531 - Macro Started
19:44:23:562 - 1,%A70%,%A70%
19:44:23:562 - 2,%A70%,%A70%
19:44:23:562 - 3,%A70%,%A70%
19:44:23:562 - 4,%A70%,%A70%
19:44:23:562 - Macro Finished
As you can see from the two output files listed above, the First one (UnCompiled) everything is recorded fine. But in the Second one (Compiled EXE), the %A70% is being written to the File instead of "Technical / Scripting" as expected.

When Running the Script in Debug Mode, Both strReportValue and A70 are set to "Technical / Scripting", so as you can see from the above comparisons, it's NOT the VBEVAL Statement.

I sincerely, hope that Marcus can isolate this problem and fix it ASAP with a maintenance release as it puts my whole program to a stand still if I can't compile it :)

Thank You!

Update to this Original Post..

while reading through the forum, I came across the following Post:
http://www.mjtnet.com/forum/viewtopic.php?t=4432

And wonder if I could get some explanation here on how to include the IEAuto.DLL with the Compiled EXE. I'm thinking that I'm not doing something right with this and maybe (but doubtful) that has something to do with this problem. Could someone please point me to the correct location to find information on creating a compiled EXE for distribution to another computer that won't have MS already installed on it? (Would I be violating any License issues with my Compiled EXE if it includes IEAuto.DLL?) Thank You.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jul 02, 2008 7:41 am

You're using the Imports method to access the IEAuto.DLL library. Therefore you need to copy your Imports folder to the same location as the EXE. Otherwise it has no clue what IE_Create, IE_Show, IE_Navigate, IE_Wait, IE_ExtractTag etc mean. Create an Imports folder in the same folder as the compiled EXE and make sure IEAuto.DLL and IEAuto.INI are in it.

Alternatively, to avoid using Imports, access the functions using LibFunc calls, so that you access the DLL functions directly.

Looks like you've started doing that as you've loaded the DLL with a LibLoad line. But then you've continued to use the Imported function names which will only mean anything if the Imports/IEAuto.INI file is present. Switch to using LibFunc and you can avoid this.

In WebRecorder under Tools/Output Format you can switch WebRecorder to ouput the required LibFunc lines when recording, instead of the IE_ function name which require the Imports/IEAuto.INI file for Macro Scheduler to understand them.

So the reason you're getting A70 in the output file is that the script is doing nothing and IE_ExtractTag means nothing so A70 is just a literal.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MGuyM
Junior Coder
Posts: 36
Joined: Tue Jul 24, 2007 12:59 am

Post by MGuyM » Wed Jul 02, 2008 4:50 pm

I Knew I'd get a good answer to this question.

But it raises another question. If I have to include this INCLUDES folder, does this have to be included upon distribution of the EXE to others?

Can you demonstrate or point me to a demonstration of how to accomplish this?

It sounds like it might be better for me to change all of my functions to the LIBFunc Calls instead.

When Creating an EXE, is the IEAuto.DLL included?

Thank You so much for the speedy response.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Jul 02, 2008 5:29 pm

No, the IEAuto.DLL is the WebRecorder runtime, and is not included when the macro is compiled.

If you convert to the LibFunc calling method you only need to distribute the DLL with the EXE. Yes, other users would need both the EXE and DLL. They can reside in the same folder, so a simple zip file is all you need. Or if you want to be more fancy and create an installer you could use an install creator such as the free Inno Setup: http://www.jrsoftware.org/isinfo.php

Or you could use the following technique described by Dick Lockey to embed the DLL inside the EXE and extract it before loading it with LibLoad:
http://www.mjtnet.com/blog/2008/03/11/e ... r-scripts/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MGuyM
Junior Coder
Posts: 36
Joined: Tue Jul 24, 2007 12:59 am

Post by MGuyM » Wed Jul 02, 2008 5:38 pm

Thank You for the Reply.

I think I'll explore Dick's example and see how that works.

Now I guess I get to go change all of my references in my Macro ;)

MGuyM
Junior Coder
Posts: 36
Joined: Tue Jul 24, 2007 12:59 am

Post by MGuyM » Thu Jul 03, 2008 6:47 pm

I need some clarification here:

Code: Select all

//Launch IE
IE_Create>0,IE[0]
IE_Show>IE[0],1,r

IE_Navigate>%IE[0]%,http://www.mjtnet.com/usergroup/?c=2,r
IE_Wait>%IE[0]%,r
Wait>delay
I'm recoding all of my lines, and now I have the following:

Code: Select all

//Launch IE
LibFunc>hIE,CreateIE,IE[0],0
LibFunc>hIE,ShowIE,r,IE[0],1

LibFunc>hIE,Navigate,r,%IE[0]%,http://www.mjtnet.com/usergroup/?c=2
LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay
Now, according to the documentation help for the WebRecorder, the Navigate & WaitIE Lines in the second example should have "IE[0]" instead of "%IE[0]%" and I'm not sure which way is correct. I know that the % Signs represent variables, but because of the LibFunc hIE, I'm not 100% which way is correct.

Can someone please advise?

Thanks!

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jul 03, 2008 7:01 pm

In this case it actually doesn't matter. IE[0] is the variable containing the IE reference created by CreateIE. It must be used in all subsequent functions. When used on it's own unless you are using VAREXPLICIT it does not need to be in % symbols.

You're missing a LibLoad call. The DLL needs to be loaded for this method to work:

Code: Select all

//Load IEAuto.DLL
LibLoad>ieauto.dll,hIE

//Launch IE
LibFunc>hIE,CreateIE,IE[0],0
LibFunc>hIE,ShowIE,r,IE[0],1

LibFunc>hIE,Navigate,r,%IE[0]%,http://www.mjtnet.com/usergroup/?c=2
LibFunc>hIE,WaitIE,r,%IE[0]%
Wait>delay
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MGuyM
Junior Coder
Posts: 36
Joined: Tue Jul 24, 2007 12:59 am

Post by MGuyM » Thu Jul 03, 2008 7:08 pm

I have VAREXLICIT=0 so does that mean I don't need to worry about the % signs?

I did have the LibLoad Function in my Script, I just omitted it from the post to keep it simple.

Thank You So much for the Speedy Reply.

As a General Rule, is it better to Code with %IE[0]% or should I be using IE[0]? Also, since I'm kinda new at this, and I'm only running one instance of IE, could I have just as easily used "IE" or "%IE%" instead of having the [0] Blocks? WebRecorder used the [0], so I continued to use them, but I get the feeling they are redundant and not necessary unless I have multiple browser windows open in which case it would need to address each window accordingly.

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jul 03, 2008 9:17 pm

Yes, you could even call it "fred". But IE is clearly more explanatory. WebRecorder uses IE[0] for the first instance created, and IE[1] for the next, and so on, as more than one instance can be open at one time. Hence the numerics.

Unless you are using VAREXPLICIT=1 there is no need for % symbols around a variable when it is on its own. When embedding it in a string (or other variable [e.g. when using loop counters in array type vars]), then you would need them.

E.g, by default:

Let>name=Fred
MessageModal>name

Would reveal "Fred" in the message box.

But, if you wanted it to say "Hello Fred" you'd have to do this:

MessageModal>Hello %name%

I hope the reason is obvious. If you just did the following you'd get "Hello name":

MessageModal>Hello name

Some people prefer to use % symbols so that they know it's a variable. Either works. But never use % symbols around the variable you are creating or modifying (or you'd actually be assigning to the value of the variable) - unless that is something you really want to do.

Only time you would have to use % symbols when the var is on its own is if you use VAREXPLICIT=1 which is something more experienced programmers might prefer. Default is VAREXPLICIT=0.

There's a topic on using variables in the help file. Another on VAREXPLICIT.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MGuyM
Junior Coder
Posts: 36
Joined: Tue Jul 24, 2007 12:59 am

Post by MGuyM » Thu Jul 03, 2008 10:12 pm

Thank You So Much for the Explanation.

You always go far and above on detailing what needs to be answered.

I appreciate it.

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sat Jul 05, 2008 5:01 pm

Just a comment about using %variable signs%.

One advantage that I find to using %variable signs% is that when you read the log file, you see the value of the variable. If you omit the %variable signs% you only see the name, and not the value. Having the value is very helpful when troubleshooting.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts