' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Threading

Class MainClass
    Private Shared size As Long = 0
    Private Shared got As Long = 0
    Public Shared Sub Main(ByVal args As String())
        Dim t As Thread = New Thread (AddressOf Download)
        t.Start
        While t.IsAlive
            if (got > 0)
                Console.WriteLine(got/size & " percent")
            Else
                Console.WriteLine("0 perecent")
            End If
            Thread.Sleep(100)
        End While
        Console.WriteLine("done")
    End Sub
    Public Shared Sub Download
        Dim req As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com/"), HttpWebRequest)
        Dim resp As HttpWebResponse = CType(req.GetResponse, HttpWebResponse)
        Dim stm As Stream = resp.GetResponseStream
        size = resp.ContentLength
        Dim fs As FileStream = File.Create("C:\ms.htm")
        Dim c As Integer
        Dim more as boolean = true
        While (more)
            c = stm.ReadByte
            If (c >= 0) Then
                fs.WriteByte(c)
                Got = Got + 1
            Else
                more = false
            End If
        End While
        stm.Close
        resp.Close
        fs.Close
    End Sub
End Class
