mIRC Home    About    Download    Register    News    Help

Print Thread
Select case #202402 21/07/08 10:38 AM
Joined: Mar 2006
Posts: 393
T
The_JD Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Mar 2006
Posts: 393
is there anything like "select case"/"switch"?

eg:

Code:
case $1 {
 :001 return we got 001
 :002 echo -a Something else
 :default echo -a Default case
}


at the moment im using something like that, but with Goto...

eg
Code:
goto $1
 :001
  { return we got 001 | goto break }
 :002
  { echo -a Something else | goto break }
 :break
 


(no default)

Is there a cleaner way to do this?

Last edited by The_JD; 21/07/08 11:39 AM.

[02:16] * Titanic has quit IRC (Excess Flood)
Re: Select case [Re: The_JD] #202404 21/07/08 11:23 AM
Joined: Jul 2008
Posts: 24
W
WhipLash Offline
Ameglian cow
Offline
Ameglian cow
W
Joined: Jul 2008
Posts: 24
Im gonna ask the really dumb question:

What case are we talking about? Cause 001 is ascii for some special character, and 002 is the ascii for bold.

As for case:
Quote:
$islower(text)
Returns $true if text is all lower case.

$isupper(text)
Returns $true if text is all upper case.



But somehow i think mean the control codes..


=======================
Count WhipLash
Services Administrator
KnightNet
=======================
Re: Select case [Re: WhipLash] #202405 21/07/08 11:35 AM
Joined: Mar 2006
Posts: 393
T
The_JD Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Mar 2006
Posts: 393
Lol Sorry I mean a function that is similar to PHP's switch function...

See http://au2.php.net/switch


[02:16] * Titanic has quit IRC (Excess Flood)
Re: Select case [Re: The_JD] #202406 21/07/08 12:02 PM
Joined: Jul 2008
Posts: 24
W
WhipLash Offline
Ameglian cow
Offline
Ameglian cow
W
Joined: Jul 2008
Posts: 24
Ah....
While i prsonally cant answer this, but i'd also like to know.


=======================
Count WhipLash
Services Administrator
KnightNet
=======================
Re: Select case [Re: The_JD] #202410 21/07/08 02:17 PM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
There is presently no CASE structure in mIRC, though it has been requested many times.

I've seen it simulated with goto and labels.

-genius_at_work

Re: Select case [Re: genius_at_work] #202412 21/07/08 03:56 PM
Joined: Mar 2006
Posts: 393
T
The_JD Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Mar 2006
Posts: 393
So I guess the way I'm doing it is the way to go then


[02:16] * Titanic has quit IRC (Excess Flood)
Re: Select case [Re: The_JD] #202413 21/07/08 05:14 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
why not just do

Code:
if ($1 == 001) { echo -a we got 001 }
elseif ($1 == 002) { echo -a we got 002 }


Anyone who says "but that's so much more code!" probably also believes in Santa Claus. It only starts becoming "more" after 10 cases at least, and anything more than 10 cases shouldn't even be a case switch anymore in mIRC-- there are many better ways to code a decision list for large decision item lists.



- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Select case [Re: The_JD] #202416 21/07/08 08:15 PM
Joined: Sep 2005
Posts: 2,878
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,878
You can use default cases with your method like this:

Code:
var %a = $1
goto %a
 :001
  { return we got 001 | goto break }
 :002
  { echo -a Something else | goto break }
 :%a
  { default case code here }
 :break

Re: Select case [Re: hixxy] #202436 22/07/08 01:48 PM
Joined: Mar 2006
Posts: 393
T
The_JD Offline OP
Fjord artisan
OP Offline
Fjord artisan
T
Joined: Mar 2006
Posts: 393
Originally Posted By: argv0
why not just do

Code:
if ($1 == 001) { echo -a we got 001 }
elseif ($1 == 002) { echo -a we got 002 }


Anyone who says "but that's so much more code!" probably also believes in Santa Claus. It only starts becoming "more" after 10 cases at least, and anything more than 10 cases shouldn't even be a case switch anymore in mIRC-- there are many better ways to code a decision list for large decision item lists.



I'm using it to display all error messages in a large script

Originally Posted By: hixxy
You can use default cases with your method like this:

Code:
var %a = $1
goto %a
 :001
  { return we got 001 | goto break }
 :002
  { echo -a Something else | goto break }
 :%a
  { default case code here }
 :break


Very nice idea... Dont know why I didnt think of that... Imma use it :P


[02:16] * Titanic has quit IRC (Excess Flood)
Re: Select case [Re: argv0] #202833 31/07/08 09:17 AM
Joined: Apr 2003
Posts: 342
M
MeStinkBAD Offline
Fjord artisan
Offline
Fjord artisan
M
Joined: Apr 2003
Posts: 342
Originally Posted By: argv0
why not just do

Code:
if ($1 == 001) { echo -a we got 001 }
elseif ($1 == 002) { echo -a we got 002 }


Anyone who says "but that's so much more code!" probably also believes in Santa Claus. It only starts becoming "more" after 10 cases at least, and anything more than 10 cases shouldn't even be a case switch anymore in mIRC-- there are many better ways to code a decision list for large decision item lists.


The amount of code is irrelevant. It's about clean looking code that can be easily understood by a quick glance. Cleaner code makes it easier to spot mistakes, resolve bugs, and just have a better idea of what the code is designed to do. It also makes code simpler to edit or extend.




Beware of MeStinkBAD! He knows more than he actually does!
Re: Select case [Re: MeStinkBAD] #202841 31/07/08 05:21 PM
Joined: Jul 2006
Posts: 3,621
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,621
Originally Posted By: MeStinkBAD
The amount of code is irrelevant. It's about clean looking code that can be easily understood by a quick glance. Cleaner code makes it easier to spot mistakes, resolve bugs, and just have a better idea of what the code is designed to do. It also makes code simpler to edit or extend.
This is true, and that's why i agree with argv0, use if/esleif instead of your horrible thing is really much cleaner, more easy to read/edit/extend and i would have a better idea about what the code do with if/elseif rather than with something else.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Select case [Re: Wims] #202842 31/07/08 06:01 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
if/elseif is not the same as a select statement. Each case of a select statement cascades into the next unless explicitly told not to - this behaviour scales very poorly using if's both in terms of code readability and efficiency.

Goto is the only reasonable alternative currently, but that has a number of serious limitations too.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Select case [Re: starbucks_mafia] #202846 31/07/08 06:39 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
People rarely intentionally make use of switch cascading, though it's the only benefit. I'll bet the OP of this thread wasn't planning on it...

So the real benefit you get out of one use case is marginal, and if statements really aren't any more unreadable than goto switches when used normally. Like I said before, you don't want to have 10+ consecutive if statements in ONE alias/event just like you don't want to have 10+ consecutive switch cases in one alias/event.. they're both going to be equally large and unmanageable chunks of code. It's not about syntax, it's about size.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Select case [Re: argv0] #202855 31/07/08 09:22 PM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Then again using cascading to your benefit could possibly be a very efficient and descriptive way of writing a routine.

It's funny that in languages that do have switch/select statements alot of whisper hits the scene to get rid of elseif'ing as coding practise. Funny sidenote: VB's Select case doesnt even cascade.

For that reason if this ever were to be implemented we should stick to switch/case/default as keywords and starbucks_maffia suggestion:
Quote:


In addition to the switch/case/default suggestion here I'll tag on a suggestion for an "else" clause in place of "default" which only triggers if no other cases have triggered (basically a "default" which can't be cascaded into).

definitely has my vote.

Last edited by Mpdreamz; 31/07/08 09:31 PM.

$maybe