MODI OCR Issues, Macro Scheduler crashing to desktop

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Krep
Junior Coder
Posts: 32
Joined: Thu Nov 12, 2009 3:56 pm

MODI OCR Issues, Macro Scheduler crashing to desktop

Post by Krep » Thu Nov 12, 2009 4:55 pm

EDIT: previously this was a question that Marcus helped with below... since he's answered it I edited my original question to provide the solution at the top of the thread instead of having to scroll the bottom...

So I have been trying to get the MODI to work using the VBScript code posted here on the forum, and had some problems where, if the picture that is OCR'd doesn't contain recognizable text, the VBScript throws an error. Some improved code, generously suggested by Marcus, to catch that error is below.


Code: Select all

VBStart
Function DoOCR(bitmapfile)
  Dim miDoc
  Dim miLayout
  Dim stringOut

  set miDoc=CreateObject("MODI.Document")
  miDoc.Create (bitmapfile)
  ' Perform OCR.
  on error resume next
  miDoc.Images(0).OCR
  if Err.Number = 0 then
    set miLayout = miDoc.Images(0).Layout
    stringOut=miLayout.Text
    'MsgBox(stringOut)
    DoOCR = stringOut
  end if
  Set miLayout = Nothing
  Set miDoc = Nothing
End Function
VBEND
//Use OCR to get text from active window
VBEval>DoOCR("filename.bmp"),TheText

//Display the text
MessageModal>TheText


Hope it helps!
Last edited by Krep on Fri Nov 13, 2009 12:41 am, edited 2 times in total.

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 Nov 12, 2009 5:02 pm

Macro Scheduler's VBScript is Microsoft VBScript. So yes, it does support ON ERROR RESUME NEXT. Probably native VBScript crashes here too. As well as on error resume next you probably need to CATCH that error and then NOT process the rest of the code. So you want to see if an error occurred after that line and if so do not continue, as that is what is causing the crash.

i.e.

On Error Resume Next
..
..
miDoc.Images(0).OCR
if Err.Number = 0 then
..
.. rest of code
End If
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Krep
Junior Coder
Posts: 32
Joined: Thu Nov 12, 2009 3:56 pm

Post by Krep » Thu Nov 12, 2009 6:24 pm

I will give that a shot.

That doesn't make complete sense to me though, because I would have expected all subsequent errors to also be "skipped" due to the "Resume Next" statement.

Krep

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 Nov 12, 2009 7:17 pm

Yes, but there are VBScript errors and then there are Access Violations and so on. The subsequent error is not a VBscript error. You're trying to manipulate external libraries here. Just trying to carry on and issue commands in the MODI library after you've already had a VBScript error doesn't seem sensible to me. If you get a VBScript error at that miDoc.Images(0).OCR line then I would expect further manipulation of the miDoc object to fail.

Now, we can argue over whether or not MODI should crash or not, and we can discuss ideologies until the cows come home, but since neither of us developed it and neither of us have the MODI code to hand that would probably be pointless.

What we DO know is that you sometimes get a VBScript error at that line. And you also know that WHEN we get that error nasty things happen later on if we execute the subsequent code. So let's HANDLE that error and then NOT call the later code that causes the nasty things. To me that's the logical thing to do.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

Krep
Junior Coder
Posts: 32
Joined: Thu Nov 12, 2009 3:56 pm

Post by Krep » Thu Nov 12, 2009 9:41 pm

Thanks so much for your help Marcus, and BTW - your program is fantastic! I know this MODI stuff is not your program and you are just supporting someone else's code as far as that goes, so thanks for the help you have been able to provide.

I'll give that a try and if I get it to work I'll post an example of improved working MODI VBScript code with working error handling should the page be blank.... I've been looking over the MODI help on Microsoft's website and also am wondering if there should be a line in the VBScript to wait for the OnOCRProgress flag to indicate OCR is finished prior to accessing the text, or maybe that doesn't apply to the miDoc.Images(0).OCR method... (Will do some experimenting)...

Is there a good way to debug VBScript code? Watch variables and so forth? Sorry I am new to VBScript...

Krep

Krep
Junior Coder
Posts: 32
Joined: Thu Nov 12, 2009 3:56 pm

Post by Krep » Fri Nov 13, 2009 12:35 am

It works! So I will just edit my message above with the updated code, so its at the top of the thread...

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