Error Message: WordBasic Err=39! Case Else Expected

Last reviewed: July 30, 1997
Article ID: Q97173
The information in this article applies to:
  • 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) = "Please enter a number between 1 and 3" Musicians$(1) = "Jimi Hendrix" Musicians$(2) = "Buddy Holly" Musicians$(3) = "Elvis Presley"

Input "Enter a number from 1 to 3", Musician

Select Case Musician Case 0 To 3

   Print Musicians$(Musician)
Case Else
   Print "Enter a number between 1 and 3."
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) = "Please enter a number between 1 and 3" Musicians$(1) = "Jimi Hendrix" Musicians$(2) = "Buddy Holly" Musicians$(3) = "Elvis Presley"

Input "Enter a number from 1 to 3", Musician

Select Case Musician Case 0 To 3

   Print Musicians$(Musician)
End Select

Done:

End Sub


KBCategory: kbmacro
KBSubcategory:
Additional query words: 1.0 1.10 1.10a 2.0 2.0a 2.0a-CD 2.0b
winword2 winword 2.0c


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.