Re: Select Case vs. ElseIf



On 18 Oct 2005 21:06:02 -0700, "Lauren Quantrell"
<laurenquantrell@xxxxxxxxxxx> wrote:

>I tend to have a lot of
>
>SELECT CASE x
>CASE x1
>
> SELECT CASE y
> CASE y1
> CASE y2
> END SELECT
>
>CASE x2
>etc.
>END SELECT

There's usually a way to unstack these, and greatly improve reuse and
mainainability in the process. Try to set it up so that the X cases write
parial results to variables, then a separate block for Y finishes the job.

For instance, If you start with something like this...

Select case X
Case -1
Select Case Y
Case -1: Cell = "Top Left"
Case 0: Cell = "Left"
Case 1: Cell = "Bottom Left"
End Select
Case 0
Select Case Y
Case -1: Cell = "Top"
Case 0: Cell = "Center"
Case 1: Cell = "Bottom"
End Select
Case 1
Select Case Y
Case -1: Cell = "Top"
Case 0: Cell = "Center"
Case 1: Cell = "Bottom"
End Select
End Select

.... you can rewrite it like this...

Select case X
Case -1: XText = "Left"
Case 1: XText = "Right"
End Select

Select case Y
Case -1: YText = "Top"
Case 1: YText = "Bottom"
End Select

Cell = XText & " " & YText
If Cell = " " Then Cell = "Center"
.



Relevant Pages

  • Re: Punctuation and/or Wording Help Needed --- Badly :-)
    ... > Here's my rewrite (I've left the word "mysical" as in the original, ... > Doors can be excellent symbols of mysical knowledge: ... Who, or what, would be doing the imposing? ... Prev by Date: ...
    (alt.usage.english)
  • Re: PHP error if MySQL server is down
    ... >>> would like the page to show anyway without any error messages but with an ... >> I'd suggest to rewrite your code in something like this: ... My bookmarks: ... Prev by Date: ...
    (alt.php)
  • Re: analytic prolongation
    ... >Hi David, ... I forgot to write the constant inside the product, so I rewrite ... here's a general solution to the problem of finding an ... Prev by Date: ...
    (sci.math)
  • Re: getWindowText in Child Dialog
    ... Thank you, that is all very informative, but I have decided to scrap my ... dialog based project and rewrite it in a form based project using a ... Thanks again, Dave. ... Prev by Date: ...
    (microsoft.public.vc.mfc)
  • Re: German annexations.
    ... > rewrite it, and almost certainly will before the next day's sun can ... Cthulhu na prezydenta! ... Prev by Date: ...
    (soc.history.war.world-war-ii)

Loading