472,146 Members | 1,393 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

Select Case statement with multiple varaibles

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

Dec 11 '06 #1
1 21359

"microsoft.public.dotnet.languages.vb" <ma******@hotmail.comwrote in
message news:11**********************@80g2000cwy.googlegro ups.com...
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...71eefb3b01.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...63a9bdb241.asp
Anthony.

Dec 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ralph Freshour | last post: by
17 posts views Thread by kalamos | last post: by
4 posts views Thread by Ian Richardson | last post: by
6 posts views Thread by dbuchanan | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.