在VB中Webbrowser打开网页的问题!
我知道用Webbrowser打开单个网页的方法,但现在如果我有很多个网页例如10个,存在txt文件中,我要从第一个网址开始打开,打开后暂停5秒,然后关掉,再打开下个网址。...
我知道用Webbrowser打开单个网页的方法,但现在如果我有很多个网页例如10个,存在txt文件中,我要从第一个网址开始打开,打开后暂停5秒,然后关掉,再打开下个网址。一直到十个网页全部开过一遍,结束!请高手指点这个应该怎么写?谢谢!
展开
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
'***************************************************************
在当前目录下建立一个文本文档"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
'***************************************************************
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询