我是 VB6 新手,我有一个使用网络浏览器建立互联网连接的项目。生成它的函数位于下面描述的模块中,项目在主窗体中调用它。
表格:
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
它在 WB.Navigate2
行中返回错误 Object required
。如果我把这个函数放在 Forms 中,它就可以正常工作。如何在模块内声明网络浏览器?我尝试使用 Dim WB as New WebBrowser_V1
但出现另一个错误:对象不支持此属性或方法
最佳答案
我只是引用主表单解决了这个问题:
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
关于mysql - VB6 在模块中声明网页浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54439139/