Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Basic 6.0 Case Statement

Tags:

vb6

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
like image 946
Joe Winfield Avatar asked Dec 21 '11 18:12

Joe Winfield


People also ask

What is a case statement in Visual Basic?

A Select Case statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each select case.

What is the syntax of select case?

Syntax of Select Case Statement in VB.Netyour_expression: this denotes an expression which evaluates to one of the elementary Data Types supported in Microsoft VB.NET. expression_list: expression clauses that denote the match values for the expression. For the case of multiple clauses, separate them using a comma (,).

Are Visual Basic keywords case sensitive?

Visual Basic is case-insensitive, but the common language runtime (CLR) is case-sensitive. For more information, see "Case Sensitivity in Names" in Declared Element Names.


1 Answers

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

like image 180
nybbler Avatar answered Sep 20 '22 06:09

nybbler