Microsoft KB Archive/97173

-

{| The information in this article applies to:
 * width="100%"|
 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c

SYMPTOMS
A Word for Windows macro stops and returns the following error message when you pass a value that is outside the range of defined cases in a Select Case statement:

WordBasic Err=39! Case Else Expected You should add a Case Else statement to your macro that includes instructions for undefined Case values.

MORE INFORMATION
The macro below gives an example of a valid Case Else statement.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code 'as is' without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Sub MAIN Dim Musicians$(3) Musicians$(0) = &quot;Please enter a number between 1 and 3&quot; Musicians$(1) = &quot;Jimi Hendrix&quot; Musicians$(2) = &quot;Buddy Holly&quot; Musicians$(3) = &quot;Elvis Presley&quot; Input &quot;Enter a number from 1 to 3&quot;, Musician

Select Case Musician Case 0 To 3

Print Musicians$(Musician) Case Else Print &quot;Enter a number between 1 and 3.&quot; End Select Done:

End Sub Note: Case statements look for numeric variables. Alphabetic characters are interpreted as 0 (zero). When you write a macro, be sure your Case statements account for the possibility of alphabetic instead of numeric input.

Sample Macro That Causes Error Message
In the following sample macro, if you enter one of the four defined variables (namely, 0, 1, 2, or 3), the macro runs correctly. If you enter any other number (such as 5), the Select Case statement cannot interpret the input and returns the error message.

Sub MAIN Dim Musicians$(3) Musicians$(0) = &quot;Please enter a number between 1 and 3&quot; Musicians$(1) = &quot;Jimi Hendrix&quot; Musicians$(2) = &quot;Buddy Holly&quot; Musicians$(3) = &quot;Elvis Presley&quot; Input &quot;Enter a number from 1 to 3&quot;, Musician

Select Case Musician Case 0 To 3

Print Musicians$(Musician) End Select Done:

End Sub
 * }

-

Last reviewed: July 30, 1997

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.