![]() |
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 |
Re: Select Case statement with multiple varaibles
"microsoft.public.dotnet.languages.vb" <mamun_ah@hotmail.com> wrote in message news:1165815937.193502.129340@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. |
| All times are GMT. The time now is 02:37 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.