• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1590
  • Last Modified:

HTMLDocument - Type Mismatch

I am painfully trying to navigate a site and this is now a blocking problem.

I want to read some code from some JavaScript, and I get a Type Mismatch error when I try to call the procedure that is intended to read the source data,  using the document object as a parameter.

I test the type before calling the procedure, but it still produces an error.

This is the calling code:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)

'...
    On Error GoTo DocumentCompleteError
'...
                        WriteLog "GetSiteList WebBrowser1.document.frames(0).document type: " & TypeName(WebBrowser1.document.frames(0).document)
                        GetSiteList WebBrowser1.document.frames(0).document
'...
DocumentCompleteError:
WriteLog "DocumentCompleteError: " & Err.Number & ", " & Err.Description
    Select Case Err.Number
        Case 0
        Case 438
            DoEvents
            Sleep 1000
            Resume
        Case 13
            Stop
            Resume
        Case Else
            Stop
            Resume Next
    End Select
End Sub

This is the called code

Sub GetSiteList(Doc As HTMLDocument)
    Dim sc As HTMLHtmlElement
    Dim ScriptLines
    Dim i As Integer
    Dim j As Integer
    Dim p As Integer
    Dim q As Integer
    On Error GoTo GetSiteListError
    WriteLog "In GetSiteList: " & TypeName(Dic)
    WriteLog "GetSiteList. Element count: " & Doc.All.length
    For Each sc In Doc.All
   
        If sc.tagName = "SCRIPT" Then
            WriteLog "GetSiteList. Script found"
...
End Sub

This is the logging code:

Sub WriteLog(Text As String)
    Dim f As Integer
    Dim strFileName As String
    strFileName = strLogPrefix & Format$(Now, "yy") & Format$(Format$(Now, "y"), "000") & ".log"
    Text = Format$(Now, "HH:nn:ss") & " " & Text
    Debug.Print Text
    f = FreeFile
    Open App.Path & "\" & strFileName For Append As #f
        Print #f, Text
    Close #f
End Sub

and this is what gets logged.

16:20:16 GetSiteList WebBrowser1.document.frames(0).document type: HTMLDocument
16:20:16 DocumentCompleteError: 13, Type mismatch

There is no log data from the called procedure, so the error must be in the call, but my log reports that the object type is what  the Sub is expecting. Help!
0
GrahamSkan
Asked:
GrahamSkan
  • 4
  • 2
1 Solution
 
Erick37Commented:
The DocumentComplete event will fire once for each frame in the document, and then once at the end of the entire document.  If you need to access the entire document and ignore the event during the loading of subframes, use:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    If (pdisp Is WebBrowser1.Object) Then
        'The entire document has loaded
0
 
GrahamSkanAuthor Commented:
Thanks Erick37. I do have that line in the code.The problem is that I actually read the object type just before the call. It is reported as HTMLDocument, but still gives an error.
0
 
anthonywjones66Commented:
Try:-

Sub GetSiteList(Doc As IHTMLDocument2)

TypeName is an unreliable way to determine type since it just returns a class name.  Having the same class name is not a guarantee of which interfaces are implemented. Also the default interface for HTMLDocument is a DISP interface.  I don't think VB can use it.

Anthony.


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
GrahamSkanAuthor Commented:
Thanks for that Anthony.
I did find that that

TypeOf Doc Is HTMLDocument

returned false, so I just called but I don't know what other objects to test it against. I could get past the error by decaring it as Object type, but then I was into guessing what properties and methods were available.

I'll try your recommendation.
0
 
anthonywjones66Commented:
You can find out what is available from here.

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_document.asp

The Disp interface (the one used by scripts in the browser) is simply a collection of all the members from IHTMLDocument2, 3, 4, 5 and IHTMLDOMNode, 2.  

For what you are doing IHTMLDocument2 is what you want.  For Each through Doc.scripts collection will be faster than using all.

I'm not sure innerText will give you access to what you want.  If not then the IHTMLScriptElement interface has a text property and that will.

On the hand you can use object every where and use the above documentation as a guide to what you can do.

Anthony.



Anthony.
0
 
GrahamSkanAuthor Commented:
Thanks for that additional advice. Saturday evening has started here, so I'll try that tomorrow.
0
 
GrahamSkanAuthor Commented:
Thanks very much
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now