Single line VBScript Select Case with multiple statements: eg: Case 0: x=a y=b

1.3k Views Asked by At

I'm randomly selecting a flag and corresponding country using VBScript. Because of the way I'm generating the code (programmatically), each Case statement will end up on a single line.

I know to use the colon (":") after the Case x: to keep the flag var on the same line. Adding the country var to the line breaks the code though.

What is the proper syntax for this line?

Current code sample:

Select Case rndCountry
Case 0: flag="af" country="Afghanistan"
Case 1: flag="al" country="Albania"
Case 2: flag="dz" country="Algeria"
Case 3: flag="as" country="American Samoa"
Case 4: flag="in" country="Andaman Islands"
Case 5: flag="ad" country="Andorra"
Case 6: flag="ao" country="Angola"
Case 7: flag="ai" country="Anguilla"
Case 8: flag="aq" country="Antarctica"
Case 9: flag="ag" country="Antigua and Barbuda"
Case 10: flag="ar" country="Argentina"
Case 11: flag="am" country="Armenia"
Case 12: flag="aw" country="Aruba"
Case 13: flag="ac" country="Ascension Island"
End Select

The above code yields the "Expected end of statement" error.

2

There are 2 best solutions below

0
user692942 On BEST ANSWER

VBScript uses new lines to determine where one statement starts and another one begins, but you can use a colon to terminate a statement instead which allows you to span multiple statements across one line.

For example:

Case 0: flag="af": country="Afghanistan"

Is the equivalent of:

Case 0
  flag="af"
  country="Afghanistan"
0
Kringle On

No sooner do I post than I figure it out :-)

The correct syntax is:

Case 0: flag="af": country="Afghanistan"

Note that the following also works:

Case 0: flag="af": country="Afghanistan":

In short, colons are needed after each variable to keep everything on one line of code.