Select Case statement with multiple varaibles

Discussion in 'ASP General' started by microsoft.public.dotnet.languages.vb, Dec 11, 2006.

  1. Hi All,

    I wanted to know whether this is possible to use multiple variables to
    use in the select case statement such as follows:

    select case dWarrExpDateMonth, dRetailDateMonth
    case "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan"
    case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb"
    End Select

    The reason is I have several date varaibles (mmddyy format) and I want
    to display the months in word such as above. Right now I have repeated
    the same select case statement for different variables. I was wondering
    how can I avoid repeating the select case statement for different
    variables which will be nothing but different months.

    Thanks a million in advance.
    Best regards,
    mamun
    microsoft.public.dotnet.languages.vb, Dec 11, 2006
    #1
    1. Advertising

  2. "microsoft.public.dotnet.languages.vb" <> wrote in
    message news:...
    > Hi All,
    >
    > I wanted to know whether this is possible to use multiple variables to
    > use in the select case statement such as follows:
    >
    > select case dWarrExpDateMonth, dRetailDateMonth
    > case "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan"
    > case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb"
    > End Select
    >
    > The reason is I have several date varaibles (mmddyy format) and I want
    > to display the months in word such as above. Right now I have repeated
    > the same select case statement for different variables. I was wondering
    > how can I avoid repeating the select case statement for different
    > variables which will be nothing but different months.
    >
    > Thanks a million in advance.
    > Best regards,
    > mamun
    >


    I think you're quite confused as to the Select Case syntax. You should RTM
    here:-

    http://msdn.microsoft.com/library/en-us/script56/html/91c340af-8ceb-4f46-86fa-7871eefb3b01.asp


    In all VB dialects a new line delimits one statement from another. The
    colon : is also such a delimiter allow mulitple statements to appear on one
    line. A common use of : in VB is in a Case statement:-

    Select Case testExpression
    Case expression : somevar = "some literal"
    Case expression : somevar = "some other literal"
    End Select

    but this is just short hand for:-

    Select Case testExpression
    Case expression
    somevar = "some literal"
    Case expression
    somevar = "some other literal"
    End Select

    Any case block can contain any number of statements which are only executed
    if it's expression it the first one in the list of expressions to match the
    testExpression.

    Hence this is possilbe:-


    Select case dWarrExpDateMonth
    Case "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan"
    Case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb"
    End Select

    However note that you can only have one test expression.

    At guess though I think you may have expected that dWarrExpDateMonth and
    dRetailDateMonth to contain differerent values yet be resolved to their
    appropriate abbreviation.

    In that case a Function is a more appropriate solution:-

    Function CvtToMonthAbbrv(rsIn)
    Select Case rsIn
    Case "01" : CvtToMonthAbbrv="Jan"
    Case "02" : CvtToMonthAbbrv="Feb"
    End Select
    End Function

    dWarrExpDateMonth = CvtToMonthAbbrv(dWarrExpDateMonth )
    dRetailDateMonth= CvtToMonthAbbrv(dRetailDateMonth)

    Having said all that (for the purpose of education) the true solution to
    your problem is that VBScript already has such a function built in :-

    dWarrExpDateMonth = MonthName(CInt(dWarrExpDateMonth), True)
    dRetailDateMonth= MonthName(CInt(dRetailDateMonth), True)

    http://msdn.microsoft.com/library/en-us/script56/html/99221560-8a0a-4f65-a2c2-f263a9bdb241.asp


    Anthony.
    Anthony Jones, Dec 11, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. So
    Replies:
    1
    Views:
    357
    Mircea Pleteriu
    May 4, 2005
  2. So
    Replies:
    0
    Views:
    427
  3. Cheng Mo
    Replies:
    4
    Views:
    546
    Gianni Mariani
    Dec 2, 2004
  4. =?Utf-8?B?YW1qYWQ=?=

    session varaibles with asp.net urgent help

    =?Utf-8?B?YW1qYWQ=?=, Jul 7, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    2,135
  5. palmiere
    Replies:
    1
    Views:
    379
    Erwin Moller
    Feb 9, 2004
Loading...

Share This Page