473,287 Members | 3,228 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 21616

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ralph Freshour | last post by:
I have a question about the following PHP script - I got it off a web site tutorial on how to count users logged into your site - my question is the $PHP_SELF variable - it writes the name of the...
2
by: Omavlana | last post by:
Hi, I want to create a temporary table and store the logdetails from a.logdetail column. select a.logdetail , b.shmacno case when b.shmacno is null then select...
1
by: avinash | last post by:
hi myself avi i am developing one appliacaion in which i am using vb 6 as front end, adodb as database library and sql sever 7 as backend. i want to update one table for which i required data from...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
4
by: Ian Richardson | last post by:
Hi, The function I've put together below is a rough idea to extend a SELECT list, starting from: <body> <form name="bambam"> <select id="fred"> <option value="1">1</option> <option...
3
by: atrottier | last post by:
I'am new here so I'd like to say hello and this seems to be a great site it has already helped me a few times. I just got an assignment to correct and modify a simple access application. First some...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
3
by: CEO123 | last post by:
Does anyone know if it is possible and the syntax to test mutlitple expressions in a select case statement? This is the best I could come up with but it doesn't appear to be working Example: ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.