12
votes

This little piece of code is supposed to fire off and give me the correct variable but no matter what is in the variable "numericDay", the Variable "suffix" gives me "th". i don't see why it wouldn't change when the value of "numericDay changes both are string variables.

    Select Case numericDay
            Case numericDay = "1" Or "21" Or "31"
                 suffix = "st"
            Case numericDay = "2" Or "22"
                 suffix = "nd"
            Case numericDay = "3" Or "23"
                 suffix = "rd"
            Case Else
             suffix = "th"

    End Select
4
@Slaks they are both string variables. i thought i typed that but i think my original question got chopped down to size. no matter and no worries, i have seen the error in my syntax thanks to nybbler's answer.Joe Winfield

4 Answers

32
votes

You've written your select incorrectly. Try the following:

    Select Case numericDay
            Case "1", "21", "31"
                 suffix = "st"
            Case "2", "22"
                 suffix = "nd"
            Case "3", "23"
                 suffix = "rd"
            Case Else
                 suffix = "th"
    End Select

For future reference: http://www.vb6.us/tutorials/learn-if-else-and-select-statements-vb6

8
votes

According to the msdn you should have written it like this:

Select Case numericDay
        Case "1", "21", "31"
             suffix = "st"
        Case "2", "22"
             suffix = "nd"
        Case "3", "23"
             suffix = "rd"
        Case Else
         suffix = "th"
End Select
5
votes

"2" Or "22" will do a bytewise or with 2 and 22, which corresponds to 22.

0
votes

You've written your select incorrectly. Try the following

Eg: display day according to the number which is entered.

public function day_display(day as Integer) as String
   select case day
        case 1: day_display = "Sunday"
        case 2: day_display = "Monday"
        case 3: day_display = "Tuesday"
        case 4: day_display = "Wednesday"
        case 5: day_display = "Thursday"
        case 6: day_display = "Friday"
        case 7: day_display = "Saturday"
        case else: day_display = "Wrong entry."
   end select
end function   

day_display(1) will return "Sunday"