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
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