1

Im trying to get all the info i can get from a pictured doc. Which includes hand-writings in some part. While scanning this im having my screen freeze like hell and than gives an error that says VB6 stopped working... I cant really findout what causes this so i just wanna get over it if there is an error or OCR faliure. Sadly couldnt succeded yet. Here what i done so far:

Dim Mdoc As MODI.Document
Dim Mlay As MODI.Layout
Dim fso As Scripting.FileSystemObject
Dim logfile As Object

Public Function ScanMan(ByVal Name As String, ByVal Path As String) As String
    Set Mdoc = New MODI.Document
    'Set Mdoc = CreateObject("MODI.Document")
    Set fso = New Scripting.FileSystemObject

    DoEvents
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''' Create OCRLog File '''''''''''''''''''
    OCRPath = App.Path & "\OCR Results Log\"
    OCRName = Str(DateTime.Date) & " OCRresults"
    If fso.FolderExists(OCRPath) = False Then
        fso.CreateFolder (OCRPath)
    End If
    If fso.FileExists(OCRPath & OCRName & ".txt") = False Then
        fso.CreateTextFile OCRPath & OCRName & ".txt"
    End If
    Set logfile = fso.OpenTextFile(OCRPath & OCRName & ".txt", ForAppending)
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    On Error GoTo OCRErr
    DoEvents
    Mdoc.Create Path & Name
    Mimg = Mdoc.Images(0).OCR(miLANG_ENGLISH, True, True)
    Set Mlay = Mdoc.Images(0).Layout
    logfile.WriteLine Mlay.Text

    ScanMan = Mlay.Text

    Mdoc.Close False

    Set Mlay = Nothing
    Set Mdoc = Nothing

OCRErr:
    logfile.WriteLine "OCR given (" & Err.Number & ") numbered (" & Err.Description & ") error."
    logfile.Close
End Function

So how can i handle this freeze problem?

Cylian
  • 10,970
  • 4
  • 42
  • 55
Berker Yüceer
  • 7,026
  • 18
  • 68
  • 102
  • For it to crash like that, it's not likely to be an error that you can handle in VB6. At what point is it actually crashing? try single stepping through or adding debug logging to see. – Deanna Jun 01 '12 at 13:44
  • well @Deanna thats the problem i did everything look up there do you see any err can cause a total freeze with a code like that? seriously... but some how at that point always im getting (VB6 stopped working) error. I searched trough my hole project and yea only at this part this sh.. happens and even while debugging it causes this stu... err again and again. – Berker Yüceer Jun 01 '12 at 15:29

1 Answers1

1

Try this:

Mdoc.Images(0).OCR
logfile.Write Mdoc.Images(0).Layout.Text

Hope this helps.

Cylian
  • 10,970
  • 4
  • 42
  • 55