Several uses of the inet control

Source: Internet
Author: User
Tags date file size
Control Inet control supports HTTP and FTP two kinds of communication protocols. With this control, you can accomplish a number of functions.

Let's take a look at it by example.



Environmental VB6+WINXP

Open VB6, New project

Add a part Microsoft Internet Transfer Controls.

Add 2 buttons to the form, 2 text boxes, and inet controls

The code is as follows:



Option Explicit

' This code uses the GetHeader to return the page information, more accurate some

' Can get file last modified date, file size, etc.

' In this way you can also determine whether a file exists

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

' You can see all the items

MsgBox Inet1.getheader



' Get modified date time is green time, convert it to the Times

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 "Success"

Case 404

MsgBox "no discovery."

Case Else

MsgBox "Error"

End Select

End Sub



' This code simply determines if it's connected to the Internet

' If connected, get the source page and save

Private Sub Command2_Click ()

Inet1.cancel

If Len (Inet1.openurl ("http://localhost/xml\tt.htm")) <> 0 Then

MsgBox "Already Connected"

Text2.text = Inet1.openurl ("http://localhost/xml\tt.htm")

If inet1.stillexecuting Then

DoEvents

End If

' Save to File

Open App.Path & "\index.htm" for Output as #1

Print #1, Text2.text

Close #1

Else

MsgBox "No Connection"

End If

End Sub.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.