• Support
  • Articles
  • Resources
  • Products

Screen Scrape Example

Moderator: boris

1 postPage 1 of 1

cwaters
Newbie

Posts:
22
Joined: Wed Jun 18, 2008 10:00 pm
by cwaters » Thu Aug 21, 2008 9:57 pm
This is in regard to thread: http://logmett.com/forum/viewtopic.php?f=2&t=874

This macro is pretty much like a CASE statement that looks for various things and when it finds a specific match, it executes an action. This may be fairly complex as I use a couple of different methods to find information, but demonstrates how to capture information on a fixed size terminal window. A few variations might make it possible to gather data from a variably sized window if there were unique static things to key on, but I didn't need to do that in my environment.

This macro is mapped to a keystroke combo and works from several different screens, thus the first section acts very much like a CASE statement in other languages.

I hope this helps someone.

Code: Select all

  1. ;;  Macro for screen scraping
  2. ;;  Version RC1.5
  3. ;;  Mod Date:  08/15/2008
  4. ;;  Written by Chris Waters
  5.  
  6.  
  7. ;;  This sections copies the screen to the clipboard and then clears the selection
  8.  
  9. callmenu 50280
  10. callmenu 50210
  11. callmenu 50270
  12.  
  13. ;;  Creates a variable called page from the clipboard
  14.  
  15. clipb2var page
  16.  
  17. ;;  Enable/Disable debug messaging  0=debug off 1=debug on
  18.  
  19. ;debug = 1
  20. debug = 0
  21.  
  22.  
  23. ;;  Here we are looking for the screen we are on and copying the appropriate part of the top line.
  24. ;;  If no match is found it moves to the next section.  If a match is found it moves to the
  25. ;;  specified label with the 'goto' command.  A label is analogous to a subroutine.
  26.  
  27. strcopy page 22 12 type
  28.     strcompare type 'Order Browse'
  29.     if debug = 1 messagebox type 'Type Order'
  30.         if result = 0 goto Orderbrowse
  31.  
  32. strcopy page 16 20 type
  33.     strcompare type 'Order Browse- Entity'
  34.     if debug = 1 messagebox type 'Type OrderB-Entitiy'
  35.         if result = 0 goto OrderBrowseEntity
  36.  
  37. strcopy page 23 14 type
  38.     strcompare type 'History Browse'
  39.     if debug = 1 messagebox type 'Type HIST'
  40.     strcopy page 64 2 ent
  41.         if result = 0 goto HistoryScan
  42.        
  43. strcopy page 31 20 type
  44.     strcompare type 'A/R Customer Inquiry'
  45.     if debug = 1 messagebox type 'Type A/R Cust'
  46.         if result = 0 goto ARCust
  47.  
  48. strcopy page 29 23 type
  49.     strcompare type 'A/R Transaction Inquiry'
  50.     if debug = 1 messagebox type 'Type A/R Trans'
  51.         if result = 0 goto ARTrans
  52.  
  53.        
  54. strcopy page 31 20 type
  55.     strcompare type 'CIT Case Maintenance'
  56.     if debug = 1 messagebox type 'Type CIT'
  57.         if result = 0 goto CITBrowse
  58.  
  59. strcopy page 33 15 type
  60. offset=2
  61. clipb2var transpage offset
  62. strcopy transpage 177 19 subtype
  63.     strcompare type 'Billing Inquiry'
  64.     if debug = 1 messagebox type 'Type Bill'
  65.         if result = 0 do
  66.             strcompare subtype 'Transaction Details'
  67.             if debug = 1 messagebox type 'Type Trans'
  68.                 if result = 0 goto BillingTrans
  69.                
  70. strcopy page 33 15 type
  71.     strcompare type 'Voucher Inquiry'
  72.     if debug = 1 messagebox type 'Type Voucher'
  73.     if result = 0 goto Voucher
  74.  
  75.  
  76.    
  77. ;;  This is iterating through the clibpard by each maximum string length (255) and looking for the selected
  78. ;;  line.  Once found it returns the beginning position of that line as result.
  79.  
  80. :Voucher
  81. offset=0
  82. do
  83.     clipb2var page offset
  84.     strscan page 'x >'
  85.     pos = result
  86.     if pos != 0 goto Vonofoundit
  87.     offset = offset + 1
  88. loop while pos = 0     
  89.  
  90.  
  91.  
  92. :HistoryScan
  93. offset=0
  94. do
  95.     clipb2var page offset
  96.     strscan page 'x >'
  97.     pos = result
  98.     if pos != 0 goto HistScanfoundit
  99.     offset = offset + 1
  100. loop while pos = 0     
  101.  
  102.  
  103.  
  104. ;;  These copy the requried information to pass to label DLQ from static points on a given screen.
  105.  
  106. :Orderbrowse
  107.     type="OrderBrowse"
  108.     strcopy page 65 2 ent
  109.     strcopy page 68 7 orderno
  110.     if debug = 1 messagebox type 'Type of Query'
  111.     if debug = 1 messagebox ent 'Entity'
  112.     if debug = 1 messagebox orderno 'Order Number'
  113.     goto DLQ
  114. end
  115.  
  116. :OrderBrowseEntity
  117.     type="OrderBrowse"
  118.     strcopy page 38 2 ent
  119.     strcopy page 65 7 orderno
  120.     if debug = 1 messagebox type 'Type of Query'
  121.     if debug = 1 messagebox ent 'Entity'
  122.     if debug = 1 messagebox orderno 'Order Number'
  123.     goto DLQ
  124. end
  125.  
  126. :ARCust
  127.     type="CUSTNO"
  128.     strcopy page 183 6 orderno
  129.     ent="ACCOUNTS"
  130.     if debug = 1 messagebox type 'Type of Query'
  131.     if debug = 1 messagebox ent 'Entity'
  132.     if debug = 1 messagebox orderno 'Order Number'
  133.     goto DLQ
  134.  
  135. :ARTrans
  136.     offset=0
  137. do
  138.     clipb2var page offset
  139.     strscan page 'Batch No:'
  140.     pos = result
  141.     if pos != 0 goto ARTransfoundit
  142.     offset = offset + 1
  143. loop while pos = 0 
  144.    
  145.     if debug = 1 messagebox type 'Type of Query'
  146.     if debug = 1 messagebox ent 'Entity'
  147.     if debug = 1 messagebox orderno 'Order Number'
  148.     goto DLQ
  149.  
  150.  
  151. :BillingTrans
  152.     type="HistoryBrowse"
  153.     offset=3
  154.     clipb2var bigpage offset
  155.     strcopy bigpage 144 7 orderno
  156.     ent=""
  157.     if debug = 1 messagebox type 'Type of Query'
  158.     if debug = 1 messagebox ent 'Entity'
  159.     if debug = 1 messagebox orderno 'Order Number'
  160.     goto DLQ
  161. end
  162.  
  163. :CITBrowse
  164.     type="CITBrowse"
  165.     strcopy page 158 2 ent
  166.     strcopy page 148 8 orderno
  167.     if debug = 1 messagebox type 'Type of Query'
  168.     if debug = 1 messagebox ent 'Entity'
  169.     if debug = 1 messagebox orderno 'Order Number'
  170.     goto DLQ
  171. end
  172.  
  173. ;;  These Xxxxfoundit routines take the position from the current offset + 80 to grab a complete line which is then
  174. ;;  parsed into the variables to be used for the external app.
  175.  
  176. :Vonofoundit
  177.     type="VonoBrowse"
  178.     strcopy page pos 80 myline
  179.     if debug = 1 messagebox myline 'myline'
  180.     strcopy myline 4 2 ent
  181.     if debug = 1 messagebox ent 'ent'
  182.     strcopy myline 8 8 vono
  183.     if debug = 1 messagebox vono 'vono'
  184.     goto DLQ
  185. end
  186.  
  187.  
  188. :HistScanfoundit
  189.     type='OrderBrowse'
  190.     strcopy page pos 80 myline
  191.     if debug = 1 messagebox myline 'myline'
  192.     ;strcopy myline 64 2 ent
  193.     if debug = 1 messagebox ent 'ent'
  194.     strcopy myline 15 7 orderno
  195.     if debug = 1 messagebox orderno 'orderno'
  196.     goto DLQ
  197. end
  198.  
  199. :ARTransfoundit
  200.     type="BatchNo"
  201.     ent="ACCOUNTS"
  202.     strcopy page pos 80 myline
  203.     if debug = 1 messagebox myline 'myline'
  204.     if debug = 1 messagebox ent 'ent'
  205.     strcopy myline 10 12 orderno
  206.     if debug = 1 messagebox orderno 'orderno'
  207.     goto DLQ
  208.  
  209.    
  210. ;;  This section builds the path to the externalapp.exe. This could have been done differently but I wanted
  211. ;;  debug the path.
  212.  
  213. :DLQ
  214. makepath path 'C:\Program" "Files\somepath' 'externalapp.exe'
  215. myvars=""
  216. strconcat myvars type
  217. strconcat myvars ' '
  218. strconcat myvars ent
  219. strconcat myvars ' '
  220. strconcat myvars orderno
  221. strconcat path ' '
  222. strconcat path myvars
  223. if debug = 1 messagebox path 'fullpath'
  224.  
  225. ;;  Externalapp.exe was originally a vbs so I needed to call the interpreter.
  226.  
  227. wscript='wscript'
  228. strconcat wscript ' '
  229. strconcat wscript path
  230. exec wscript
  231. end
"The conclusive proof that intelligent life exists elsewhere in the Universe lies in the fact that no one has bothered to contact us." --unknown

1 postPage 1 of 1

Users browsing this forum: No registered users
cron