Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / select-case with variable?

Author
Message
Warty
16
Years of Service
User Offline
Joined: 16th Oct 2009
Location:
Posted: 7th Nov 2010 18:29
Hi, I feel pretty dumb for asking but is there a workaround for using a variable name in a select case command? Ie-



The error given is

CASE needs a literal parameter at line 65.

Reason being with so many possible message types, it will be a lot of work to make any changes to the order/number if I cannot simply reference them as above. Having all the corresponding IDs in a big type with names is easier to read/find and adjust

I am surprised this doesn't seem possible. Thanks for any help.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Nov 2010 21:41
You can either use nested IF statements:


or switch to constants:


Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Warty
16
Years of Service
User Offline
Joined: 16th Oct 2009
Location:
Posted: 8th Nov 2010 11:40
Aah constants work, that's fine, they'll never change so that's just as good. Thank you, should have tried them really.

Is there any documented reasoning as to why it is this way? Not complaining but wondering if there was a technical reason for it being so.

Although this does bring about another point, no elseif command. Sure, there is the nested else..if but that makes quite messy code after a while. Seems like it should surely be slightly more efficient to have



But that's just me being used to what I am used to thank you again for the point about constants mate!

Login to post a reply

Server time is: 2026-07-26 05:03:52
Your offset time is: 2026-07-26 05:03:52