Advantages to Select Case?

  • Thread starter Montana DOJ Help Desk
  • Start date
M

Montana DOJ Help Desk

Word 2000

I am working on an error handling routine. Initially, I was handling the
errors as follows:

If Err.Number = 5216 Or Err.Number = 5825 Then
Dialogs(wdDialogFilePrintSetup).Show
ActiveDocument.Variables("LocatesDefaultPrinter").Value =
ActivePrinter
End If
Resume Next

However, I just read about the Select Case statement. I re-wrote the above
code as shown below:

Select Case Err.Number
Case 5216, 5825
Dialogs(wdDialogFilePrintSetup).Show
ActiveDocument.Variables("LocatesDefaultPrinter").Value =
ActivePrinter
End Select
Resume Next

Both versions work, and seem to handle the errors equally well. Is there
any particular advantage to using Select Case?

-- Tom

State of Montana
Department of Justice Help Desk

"Making the world a safer place."
 
J

Jonathan West

Both versions work, and seem to handle the errors equally well. Is there
any particular advantage to using Select Case?

Two advantages for Select Case:

1. Readability. It is quick & easy to see which items are relevant

2. Grouping. You can have a single Case statement for a range of values,
like this: Case 1 To 5

One disadvantage: the branching is limited to evaluating the value of a
single expression. A set of If-ElseIf-End If has greater flexibility for
those cases where you need it.

Use whichever you feel comfortable with for different purposes.
 
M

Montana DOJ Help Desk

That's kind of what I figured. Wasn't sure, though, so just thought I'd
ask.

-- Tom

State of Montana
Department of Justice Help Desk

"Making the world a safer place."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top