Re: Select Case vs. ElseIf
- From: Steve Jorgensen <nospam@xxxxxxxxxxxxx>
- Date: Tue, 18 Oct 2005 23:09:46 -0700
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"
.
- References:
- Select Case vs. ElseIf
- From: Lauren Quantrell
- Re: Select Case vs. ElseIf
- From: John Mishefske
- Re: Select Case vs. ElseIf
- From: Lauren Quantrell
- Select Case vs. ElseIf
- Prev by Date: Re: need help
- Next by Date: checking data in one table before updating another
- Previous by thread: Re: Select Case vs. ElseIf
- Next by thread: Re: Select Case vs. ElseIf
- Index(es):
Relevant Pages
|
Loading