VB6在模块中声明Webbrowser

时间:2019-01-30 11:06:36

标签: mysql vb6 webbrowser-control

我是VB6的新手,我有一个使用webbrowser建立互联网连接的项目。使得它的功能在下面描述的模块中,并且该项目在主窗体中调用它。

表格:

Private Sub Form_Load()
    Me.Top = 585
    Me.Left = 12090

    Call BuscaPais.Paises(48, -1)
End Sub

模块BuscaPais:

Sub Paises(clifor, tempodia)

    Dim db As New ADODB.Connection
    db.Open "Driver={MySQL ODBC 3.51 Driver};Uid=root;Pwd=03072003;Server=xxx.xxx.xx.xx;Port=xxx;Option=xxx;STMT=;Database=xxx"

    SQL = "select cd_ocorrencia, vl_latitude, vl_longitude from ocorrencias where dt_hora >= date_format(date_add(current_timestamp, interval " & tempodia & " day), '%Y/%m/%d') "
    SQL = SQL & " and cd_status <> 99 and ds_pais = '' and vl_latitude <> '0.000000' and vl_longitude <> '0.000000' order by cd_ocorrencia asc "
    Set RS = db.Execute(SQL)
    While Not RS.EOF

        WB.Navigate2 "http://nominatim.openstreetmap.org/reverse?format=xml&lat=" & Replace(RS!vl_latitude, ",", ".") & "&lon=" & Replace(RS!vl_longitude, ",", ".") & "&zoom=18&addressdetails=1"
        t = Timer
        Do Until WB.ReadyState = READYSTATE_COMPLETE
            checktime = Timer - t
            If checktime >= 30 Then
                WB.Stop
                DoEvents
            End If
            DoEvents
        Loop


        If InStr(WB.Document.body.innertext, "A página XML não pode ser exibida") = 0 Then
            Pais = UCase(Mid(WB.Document.body.innertext, InStr(WB.Document.body.innertext, "</country_code>") - 2, 2))
            db.Execute ("update ocorrencias set ds_pais = '" & Pais & "' where cd_ocorrencia = " & RS!cd_ocorrencia)
        End If

        Pais = ""

    RS.MoveNext
    Wend
    RS.Close

End Sub

它在Object Required行中返回错误WB.Navigate2。如果我将此函数放入Forms中,则效果很好。如何在模块内声明Web浏览器?我尝试使用Dim WB as New WebBrowser_V1,但遇到另一个错误:Object doesn't support this property or method

1 个答案:

答案 0 :(得分:0)

我已经解决了它,只是参考了主要形式:

Sub Paises(clifor, tempodia)

    Dim db As New ADODB.Connection
    db.Open "Driver={MySQL ODBC 3.51 Driver};Uid=root;Pwd=03072003;Server=xxx.xxx.xx.xx;Port=xxx;Option=xxx;STMT=;Database=xxx"

    SQL = "select cd_ocorrencia, vl_latitude, vl_longitude from ocorrencias where dt_hora >= date_format(date_add(current_timestamp, interval " & tempodia & " day), '%Y/%m/%d') "
    SQL = SQL & " and cd_status <> 99 and ds_pais = '' and vl_latitude <> '0.000000' and vl_longitude <> '0.000000' order by cd_ocorrencia asc "
    Set RS = db.Execute(SQL)
    While Not RS.EOF

        mainform.WB.Navigate2 "http://nominatim.openstreetmap.org/reverse?format=xml&lat=" & Replace(RS!vl_latitude, ",", ".") & "&lon=" & Replace(RS!vl_longitude, ",", ".") & "&zoom=18&addressdetails=1"
        t = Timer
        Do Until mainform.WB.ReadyState = READYSTATE_COMPLETE
            checktime = Timer - t
            If checktime >= 30 Then
                mainform.WB.Stop
                DoEvents
            End If
            DoEvents
        Loop


        If InStr(mainform.WB.Document.body.innertext, "A página XML não pode ser exibida") = 0 Then
            Pais = UCase(Mid(mainform.WB.Document.body.innertext, InStr(mainform.WB.Document.body.innertext, "</country_code>") - 2, 2))
            db.Execute ("update ocorrencias set ds_pais = '" & Pais & "' where cd_ocorrencia = " & RS!cd_ocorrencia)
        End If

        Pais = ""

    RS.MoveNext
    Wend
    RS.Close

End Sub