INET控件的幾點使用
2024-07-21 02:24:40
供稿:網友
本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。inet控件支持http與ftp兩種通訊協議。利用這個控件可以完成許多功能。
我們通過例子來看看。
環境vb6+winxp
打開vb6,新建工程
添加部件microsoft internet transfer controls.
在form中添加2個按鈕,2個文本框和inet控件
代碼如下:
option explicit
'這段代碼使用了getheader來返回頁面信息,比較準確一些
'可以得到文件最后修改日期,文件大小等等
'用這個辦法還可以判斷一個文件是否存在
private sub command1_click()
dim a as string
dim str as string
dim retcode as long
inet1.openurl "http://localhost/xml/tt.htm"
if inet1.stillexecuting then
doevents
end if
'可以看到所有的項目
msgbox inet1.getheader
'得到修改日期時間是格林時間,將它轉換北京時間
str = inet1.getheader("last-modified")
str = replace(right(str, len(str) - instr(1, str, ",") - 1), "gmt", "")
text1.text = cdate(format(str, "yyyy/mm/dd hh:mm:ss"))
msgbox inet1.getheader("content-length")
retcode = val(mid(trim(inet1.getheader), 10, 3))
select case retcode
case 200
msgbox "成功"
case 404
msgbox "沒有發現"
case else
msgbox "error"
end select
end sub
'這段代碼簡單的判斷了是否與internet連接
'如果連接,得到網頁源碼并且保存
private sub command2_click()
inet1.cancel
if len(inet1.openurl("http://localhost/xml/tt.htm")) <> 0 then
msgbox "已經連接"
text2.text = inet1.openurl("http://localhost/xml/tt.htm")
if inet1.stillexecuting then
doevents
end if
'保存到文件
open app.path & "/index.htm" for output as #1
print #1, text2.text
close #1
else
msgbox "沒有連接"
end if
end sub.