' 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

Class MainClass
   Public Shared Sub Download(url As String)
      Dim req As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
      Dim resp As HttpWebResponse = CType(req.GetResponse, HttpWebResponse)
      Dim instm As Stream = resp.GetResponseStream
      Dim fnm As String = resp.Headers("Content-Disposition").Split("""")(1)
      Dim outstm As Stream = New FileStream(fnm, FileMode.CreateNew, FileAccess.Write)
      Dim b(1000) As Byte
      Dim n As Integer
      n = instm.Read(b, 0, b.Length)
      While (n > 0)
          outstm.Write(b, 0, n)
          n = instm.Read(b, 0, b.Length)
      End While
      outstm.Close
      instm.Close
      resp.Close
   End Sub
   Public Shared Sub Main(ByVal args As String())
       Dim id() As Integer = { 123, 456, 789 }
       Dim i As Integer
       For i = 1 To 3
           Call Download("http://www.domain.dk/download.asp?id=" & id(i))
       Next
   End Sub
End Class 
