API's that Suck

December 13, 2009

Sometimes Errors Don’t Matter

Filed under: Uncategorized — Grauenwolf @ 2:37 am

I have, on countless occasions, cursed the existence of “On Error Resume Next”. Why in god’s name did Microsoft see fit to include that abomination in very variant of Visual Basic is beyond me. Even VB 10 has it.

Then I needed to write a script. Just a simple loop that would download images from a web site. On the first pass it bombed because, of course, there were some images that didn’t exist. I thought about adding a simple try-catch block, then something else struck me. Sometimes errors don’t matter. Sometimes you can just keep on barreling on through without caring  what did or didn’t work because ultimately it doesn’t matter.

  1. On Error Resume Next
  2.  
  3. Dim sourcePattern = "http://www.thearma.org/Manuals/{0}.jpg"
  4. Dim targetFolder = "C:\Users\Grauenwolf\Documents\Fencing\Codex Wallerstein\ARMA Scans"
  5.  
  6. For i = 10 To 222
  7.     Dim target = IO.Path.Combine(targetFolder, i & ".jpg")
  8.     Dim source = String.Format(sourcePattern, i)
  9.     If Not IO.File.Exists(target) Then
  10.         Console.WriteLine("Downloading " & source)
  11.         My.Computer.Network.DownloadFile(source, target)
  12.     End If
  13. Next
  14. Console.WriteLine("done")

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: