G'day All.

I've just come up with these aliases which can be used to 'simulate' a switch
(for C programmers) or DO CASE (dBase) construct in batch files, which I think
are fairly useful...

These are (I think) fairly common aliases referenced in the SWITCH aliases.

      add=*set %1=%@eval[%[%1]+%2]
      sub=*set %1=%@eval[%[%1]-%2]
      dec=sub %1 1
      inc=add %1 1

Now for the switch aliases (the \ means continues on next line, don't include it
in your alias file):


      SWITCH=iff "%__SWC"=="" then^*set __SWC=1^else^\
            inc __SWC^endiff^*set __SW%__SWC=%1^\
            iff y==n then^echo > nul

      CASE=elseiff %[__SW%__SWC]==%1 then

      DEFAULT=else

      SWEND=endiff^*unset __SW%__SWC^dec __SWC^\
            if %__SWC == 0 *unset __SWC


:: example of using Switch aliases in a 4DOS batch file
inkey /k"0123456789" Enter X: %%x
inkey /k"0123456789" Enter Y: %%y
switch %x
case 1
   echo You chose X equal to 1
case 2
   echo You chose X equal to 2
default
   echo X is equal to neither 1 nor 2
   switch %y
   case 1
      echo ...but Y is equal to 1
   case 2
      echo ...but Y is equal to 2
   default
      echo ...and neither is Y.
   swend
swend

Note that switches may be nested, but take care with GOTO... the same
limitations apply as those listed in the 4DOS manual for IFF...

The environment variable __SWC is used to count the level of nesting, and to
create an intermediate variable, __SWn, where n is equal to the level of
nesting. Unless a GOTO is used to exit the switch, both (all) variables will be
undefined at the last SWEND.

Cheers
Greg  |;^)

=======================================================================

Expanding on a bit of code in the 4DOS manual gets this reasonably useful
alias set, for those who do any extensive BAT/BTM programming:

-----------(clip of ALIASES)--------------
SELECTCASE Set _Case=%[%1]^Iff x EQ y Then
CASE ElseIff %_Case %& Then
CASEELSE Else
ENDSELECT EndIff^Unset _Case
------------------------------------------

Once Alias'ed, this allows code like this to work:

SelectCase X
   Case EQ 1
      Echo A           - if %x is 1
   Case EQ 2
      Echo B           - (etc)
   Case EQ 3
      Echo C
   CaseElse
      Echo not 1,2,3   - otherwise...
EndSelect

Thought someone could use this, particularly if said someone doesn't bother
with RTFineM! :)   (Base code was on page 101 in the sample BTM shown there.)


