Methods

G

Greg Maxey

What is the advantage of Select Case over If Then ElseIf Else?



I have a variable that can be 1 of 14 preset values or a text value. I can
to this with Select Case or If Then Else If Else construction as follows.
Which is better or is either better. Thanks.



Select Case txtDateFormat.Value

Case 0

dateFormat = "mmmm dd, yyyy"

Case 1

dateFormat = "dddd, mmmm dd, yyyy"

Case 2

dateFormat = "mm/dd/yyyy"

Case etc.,

dateFormat = ".."

Case Else

dateFormat = txtDateFormat.Text

End Select



If txtDateFormat.Value = 0 Then

dateFormat = "mmmm dd, yyyy"

ElseIf txtDateFormat.Value = 1 Then

dateFormat = "dddd, mmmm dd, yyyy"

ElseIf txtDateFormat.Value = 2 Then

dateFormat = "mm/dd/yyyy"

ElseIf txtDateFormat.Value = etc., Then

dateFormat = "..."

Else

dateFormat = txtDateFormat.Text

End If
 
G

Greg Maxey

Jezebel,

I was with you until this part:

Select Case VarA
Case "Alpha", "Beta", "Gamma"

could you elaborate?
 
H

Helmut Weber

Hi everybody,

in addition, I'd would like to remark, that,
probably, if it comes to distinguish between a great many
of cases, "select case" may still work, whether "if then else if"
could return an error, similar to "formula too complex".
At least, I ran into that problem with some, let's say,
second class or minor scripting languages.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top