在VB中Webbrowser打开网页的问题!

2024-10-31 06:08:48
推荐回答(1个)
回答(1):

在窗体时加入一个webbrowser,名字默认,加入一个command名字默认,
在当前目录下建立一个文本文档"vb.txt"里边输入几个URL(一行一个).
把下列代码放到程序里:

'***********VB 延时函数定义*************************************
'声明
Private Declare Function timeGetTime Lib "winmm.dll" () As Long
'延时
Public Sub Delay(ByVal num As Integer)
Dim t As Long
t = timeGetTime
Do Until timeGetTime - t >= num * 1000
DoEvents
Loop
End Sub
'***************************************************************
'将字符串写入文件,这个函数没用到,不过可能对你会有用
Private Sub WriteFile(filePath As String, strTmp As String)
Open filePath For Output As #1
Print #1, strTmp
Close #1
End Sub
'***************************************************************
'读文件返回字符串
Private Function ReadFile(filePath As String) As String
Dim fileStr As String
Open filePath For Input As #1

Do While Not EOF(1)
Line Input #1, tem
fileStr = fileStr & tem & vbCrLf
Loop
Close #1
ReadFile = fileStr
End Function
'***************************************************************
'执行程序
Private Sub Command1_Click()
Dim url() As String
url = Split(ReadFile(App.Path & "\vb.txt"), vbCrLf)
For i = 0 To UBound(url) - 1
WebBrowser1.Navigate "about:blank"
WebBrowser1.Navigate url(i)
Delay (5)
Next
MsgBox "完毕"
End Sub
'***************************************************************