Microsoft KB Archive/43264

From BetaArchive Wiki
Knowledge Base


Variables Not Allowed in CASE Statement of SELECT CASE Block

Article ID: 43264

Article Last Modified on 11/21/2006

This article was previously published under Q43264

SUMMARY

The SELECT CASE block does not allow variables in the CASE statements. As an alternative, using multiple IF statements is recommended.

Code Example

The following code example gives a "Syntax Error" on the CASE x line:

x=1
y=1
SELECT CASE y
CASE 0
  PRINT "Zero"
CASE x                ' This line causes error
  PRINT "XXX"
CASE ELSE
END SELECT
                

This is an example of the workaround using multiple IF statements:

x=1
y=1
IF y=0 THEN
  PRINT "Zero"
ELSEIF y=x THEN
  PRINT "XXX"
ELSE
END IF
                


Additional query words: MQuickB

Keywords: KB43264