Jump to content
Macro Express Forums

Help Handling Exceptions


Recommended Posts

I need to connect to a Web-based service to poll retailer records for approximately 100 stores per day. The menu structure varies somewhat from store to store, so I need to keep track of how many Tab keys to press for each store to position the focus on the appropriate button. Easy enough; the information is all provided by a CSV control file. But what if something changes? The store could add or drop a service and that could change the number of tabs. As a result, the application could go to the wrong place.


Once I'm logged on, the window-like panels are created (apparently) by an ActiveX control. Because of this, I can't wait for the window title. I can see 4 places in the script where trouble could occur (noted below as "failure points" 1 through 4. I'm looking for a way to detect errors here and, if there is an error, stop the macro.


Variables from CSV text file:

Login (T21) - Password (T22) - Co# (T23) - Job (T24) - File Count (T25) - File (T26) - Tabs-Extract (T27)

Tabs-Job (T28) - Tabs-Close (T29) - Tabs-Exit (T30) - Retailer-directory (T31) - Project-subdirectory (T32)

Dates (T33) - OK button present (T34) - Output directory (T35) - Begin date = one year ago (T91) - End date = today (T92)


The following code-like text shows the overall structure of the macro, but is not really code.


LOGFILE:VIP.log—Starting ...
LOGFILE:VIP.log—######### Retailer %T31%
  Delete files in local download directory.
  Open browser and logg on with %T21% & %T22%.
  Use mouse to click work button. (POSITION MAY VARY depending on IE plug-ins.)
  Second log in requires the password a second time.
  The login window (a pop-up) must be selected and moved or the password cannot be entered.
  Windows from this point on do not report their names; all I can do is wait.
  Wait 10 seconds, then use Tab to position cursor on Reports button. Enter. (Failure point 1)
  Wait 10 seconds, then use Tab to position cursor on appropriate Report. Enter. (Failure point 2)
  *** IF T33 > 0
     Enter start date and end date
  *** ENDIF
  Wait for file to be ready, then click OK.
  *** IF T34 > 0
     Enter to click "OK".
  *** ENDIF
  Tab to Close button. Enter. (Failure point 3)
  Tab to Exit button. Enter. (Failure point 4)
  Close the browser.
  Connect to ftp site.
  Chage to directory specified by T31/T32/.
  Send file specified by T35\T26
LOGFILE:VIP.log—Process complete!



Link to comment
Share on other sites

I once wrote a macro to harvest a soon to be closed Yahoo Newsgroup of 36,000 messages and it taught me a lot about the difference between writing a macro to do a simple one off navigation where an occasional error is tolerable and one that needs to be able to run for hours and hours without interruption. The difference is validity checking and it usually doubles the size of my macros and is difficult to debug.


For instance with Yahoo they would occasionally take you first to a advertising screen where you had to click a button to continue but it was random. Another problem was that Yahoo would only allow so much traffic from a given IP address before it would start blocking your requests at which point I would have my macro open my router’s admin mage and do a DHCP release/renew to get a new address and continue on. But both of these problems and all other conceivable problems were solved with screen polls.


By screen poll what I mean is grabbing the contents of the screen and having ME evaluate it for validity. There are many different ways but I found the easiest was to type a CTRL+A to highlight the entire screen and move the clipcopy to a text var. Here one can scrutinize the text and make decisions on how to proceed. For instance I could see if var T1 contains “Error: Quota Exceeded” and know to execute the routine that would roll my IP address. Or maybe if it doesn’t get a valid response after so many tries it simply backs out and tries again. Or maybe it simply tags the effort as failed in your output file for you to come back to later. There are infinite options. Anyway the CTRL+A and copyclip are nearly instantaneous and innocuous so they don’t slow the macro down any. And often in cases where there might be network delays you can use them reiteratively as a makeshift “wait for ActiveX”.


Hint: In the section where ME has found an error have it use the email utility to send your phone an SMS message so it doesn’t sit there for hours doing nothing.


When I read you thing about the changes in tabs it brought back memories. Personally I have found that web developers have too much time and just like to change things for no good reason. This usually renders tab counts and mouse clicks unreliable. One workaround I’ve found is to use the find utility. I’ll do a CTRL+F and search for “Account Number:” or whatever precedes the field I desire and then issue one tab. This way I always find my mark.


Oh, and sometimes you can get all your data from the screen poll instead of navigating around the web window. Depending on the controls used and such it only works some of the time but lets say you were looking for the dollar figure next to account balance. I would set N1 to the position of “Account Balance:”, add 18 to N1 and grab the next 10 characters or whatever from the screen capture, trim and ‘Bob’s your uncle’.


The cool thing with doing all this in ME is that you don’t have to worry about all the timing issues and the process happens at the speed of light.


And if you need help developing such a macro I would be happy to lend a hand.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...