0

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.

Kringle
  • 115
  • 1
  • 5
  • Add a `:` after each statement you want on the same line, that’s what it’s for. Example `Case 0: flag="af": country="Afghanistan"`. – user692942 Apr 14 '21 at 18:21
  • Does this answer your question? [VBScript, purpose of colon?](https://stackoverflow.com/questions/1144914/vbscript-purpose-of-colon) – user692942 Apr 14 '21 at 18:23
  • Thank you user692942! I just figured it out too (palm slap) – Kringle Apr 14 '21 at 18:28

2 Answers2

0

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.

Kringle
  • 115
  • 1
  • 5
0

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"
user692942
  • 16,398
  • 7
  • 76
  • 175