In the previous lesson about Structured Error Handling, I gave you a challenge to write the example that the book promised and didn't deliver: Recode the Disk Drive Error Handler program to allow ten retries before giving up.
Here's the example from the book that needs to be recoded:
~~~~~~~~~~~~~~~~~~~~~~~~~
Try
PictureBox1.Image = _
System.Drawing.Bitmap.FromFile("a:\fileopen.bmp")
Catch
MsgBox("Insert the disk in drive A, then click OK!")
Try
PictureBox1.Image = _
System.Drawing.Bitmap.FromFile("a:\fileopen.bmp")
Catch
MsgBox("File Load feature disabled")
Button1.Enabled = False
End Try
End Try
~~~~~~~~~~~~~~~~~~~~~~~~~
Like just about every problem, this one can be programmed in an almost infinite number of ways ... and a lot of them don't even have to involve a module or procedure. So if your solution is different than mine ... Hey! Your's might be a vastly superior solution! The test is whether it really does solve the problem.
But since the goal was to use some kind of procedure, my solution does. And, as is my habit, I have thrown in a few extra features too. My solution uses a Function call to check the disk and the location of the file is a string that is passed to the Function.

