By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,417 Members | 1,825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,417 IT Pros & Developers. It's quick & easy.

Select Case

P: n/a
CJM
I'm getting a syntax error with a Select Case statement:

Select Case CSng(rs.fields("Field1"))
Case 0
Response.Write "Test1"
Case Is < 0 <<< Syntax Error
Response.Write "Test2"
Case Is > 0 <<< Syntax Error
Response.Write "Test3"
End Select

As far as I can tell the syntax *is* correct. What am I missing?

Thanks

Chris

Jun 30 '06 #1
Share this Question
Share on Google+
25 Replies


P: n/a
> I'm getting a syntax error with a Select Case statement:

Select Case CSng(rs.fields("Field1"))
Case 0
Response.Write "Test1"
Case Is < 0 <<< Syntax Error
Response.Write "Test2"
Case Is > 0 <<< Syntax Error
Response.Write "Test3"
End Select

As far as I can tell the syntax *is* correct. What am I missing?


You mean as far as you can tell, aside from the error message telling you
that the syntax is not correct???

I don't know why you're throwing "Is" in there, where did you find syntax
that looked like that?

Here is the documentation for select case:

http://msdn.microsoft.com/library/en...71eefb3b01.asp

Personally, I suggest using IF...ELSE...END IF for range vs. exact value.

f1 = CSng(rs.fields("Field1"))
if f1 = 0 then
response.write "Test1"
elseif f1 < 0 then
response.write "Test2"
else
response.write "Test3"
end if

A
Jun 30 '06 #2

P: n/a
CJM

"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:e1**************@TK2MSFTNGP02.phx.gbl...
I'm getting a syntax error with a Select Case statement:

Select Case CSng(rs.fields("Field1"))
Case 0
Response.Write "Test1"
Case Is < 0 <<< Syntax Error
Response.Write "Test2"
Case Is > 0 <<< Syntax Error
Response.Write "Test3"
End Select

As far as I can tell the syntax *is* correct. What am I missing?
You mean as far as you can tell, aside from the error message telling you
that the syntax is not correct???


Yes that's exactly what I mean. Which is why I said it.

'As far as I can tell' means, I haven't found anything to say why it may not
be syntactically correct.
I don't know why you're throwing "Is" in there, where did you find syntax
that looked like that?

It's the VB syntax. When '< 0' didn't work, I wondered if the VB syntax was
appropriate.
Here is the documentation for select case:

http://msdn.microsoft.com/library/en...71eefb3b01.asp

Which I'd already reviewed of course... It's a bit sparse, and only
indicates the obvious - that '< 0' or 'Is <0' does not qualify as a valid
expression.
Personally, I suggest using IF...ELSE...END IF for range vs. exact value.

f1 = CSng(rs.fields("Field1"))
if f1 = 0 then
response.write "Test1"
elseif f1 < 0 then
response.write "Test2"
else
response.write "Test3"
end if


Of course, this route was always open to me, but I would have rather used
Select Case for clarity.

Elsewhere I have found a comment that '=' is the only comparison operator
allowed in VBScript Select Case statement, and this operator is implicit.

It's not entirely surprising, that VBScript has such shortcomings compared
to VB, but I expected the 'official' sources to make this clear.

CJM
Jun 30 '06 #3

P: n/a
CJM wrote on 30 jun 2006 in microsoft.public.inetserver.asp.general:
Elsewhere I have found a comment that '=' is the only comparison
operator allowed in VBScript Select Case statement, and this operator
is implicit.


Try [if you are sure the field is always a number]:

what = CSng(rs.fields("Field1"))
Select Case true
Case what = 0
Response.Write "Test1"
Case what < 0
Response.Write "Test2"
Case what > 0
Response.Write "Test3"
End Select

I however prefer Aaron's if..elseif..then solution.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 30 '06 #4

P: n/a
> 'As far as I can tell' means, I haven't found anything to say why it may
not be syntactically correct.
To me, 'as far as I can tell' implies that you have found something that
says it should be syntactically correct. But that was just my
interpretation.
It's not entirely surprising, that VBScript has such shortcomings compared
to VB, but I expected the 'official' sources to make this clear.


Microsoft isn't too great on documenting the limitations in their products.
Especially ones they aren't actively developing. ;-)
Jun 30 '06 #5

P: n/a
CJM

"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message
news:uS**************@TK2MSFTNGP04.phx.gbl...
It's not entirely surprising, that VBScript has such shortcomings
compared to VB, but I expected the 'official' sources to make this clear.


Microsoft isn't too great on documenting the limitations in their
products. Especially ones they aren't actively developing. ;-)


I realise that this isnt a priority anymore, but I would have expected
better documentation precisely because ASP/VBScript has been such a key
technology over the years. And I'm surprised that more independent sources
didn't list this caveat....
Jun 30 '06 #6

P: n/a
CJM wrote:
I realise that this isnt a priority anymore, but I would have
expected better documentation precisely because ASP/VBScript
has been such a key technology over the years. And I'm surprised
that more independent sources didn't list this caveat....


What would you have them document, that incorrect syntax may not produce the
desired results?

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jun 30 '06 #7

P: n/a
> What would you have them document, that incorrect syntax may not produce
the desired results?


I was wondering what to expect.

Maybe also, "if you are used to switch in JavaScript, here is how those
differ..."

A
Jun 30 '06 #8

P: n/a
>> Which I'd already reviewed of course... It's a bit sparse, and only
indicates the obvious - that '< 0' or 'Is <0' does not qualify as a valid
expression.
but I expected the 'official' sources to make this clear.
So, the documentation indicates the obvious, but it's not clear???

Bob Lehmann
"CJM" <cj*******@newsgroup.nospam> wrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...

"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraa> wrote in message news:e1**************@TK2MSFTNGP02.phx.gbl... I'm getting a syntax error with a Select Case statement:

Select Case CSng(rs.fields("Field1"))
Case 0
Response.Write "Test1"
Case Is < 0 <<< Syntax Error
Response.Write "Test2"
Case Is > 0 <<< Syntax Error
Response.Write "Test3"
End Select

As far as I can tell the syntax *is* correct. What am I missing?
You mean as far as you can tell, aside from the error message telling

you that the syntax is not correct???


Yes that's exactly what I mean. Which is why I said it.

'As far as I can tell' means, I haven't found anything to say why it may

not be syntactically correct.
I don't know why you're throwing "Is" in there, where did you find syntax that looked like that?

It's the VB syntax. When '< 0' didn't work, I wondered if the VB syntax

was appropriate.
Here is the documentation for select case:

http://msdn.microsoft.com/library/en...71eefb3b01.asp


Which I'd already reviewed of course... It's a bit sparse, and only
indicates the obvious - that '< 0' or 'Is <0' does not qualify as a valid
expression.
Personally, I suggest using IF...ELSE...END IF for range vs. exact value.
f1 = CSng(rs.fields("Field1"))
if f1 = 0 then
response.write "Test1"
elseif f1 < 0 then
response.write "Test2"
else
response.write "Test3"
end if


Of course, this route was always open to me, but I would have rather used
Select Case for clarity.

Elsewhere I have found a comment that '=' is the only comparison operator
allowed in VBScript Select Case statement, and this operator is implicit.

It's not entirely surprising, that VBScript has such shortcomings compared
to VB, but I expected the 'official' sources to make this clear.

CJM

Jul 1 '06 #9

P: n/a
Aaron Bertrand [SQL Server MVP] wrote:
I was wondering what to expect.

Maybe also, "if you are used to switch in JavaScript, here
is how those differ..."


Even if that were the case, the syntax he provided bears no resemblance to
the JScript switch syntax, so I still am left baffled by his expectations.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jul 1 '06 #10

P: n/a

"CJM" <cj*******@newsgroup.nospamwrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
>
"Aaron Bertrand [SQL Server MVP]" <te*****@dnartreb.noraawrote in
message
news:e1**************@TK2MSFTNGP02.phx.gbl...
I'm getting a syntax error with a Select Case statement:

Select Case CSng(rs.fields("Field1"))
Case 0
Response.Write "Test1"
Case Is < 0 <<< Syntax Error
Response.Write "Test2"
Case Is 0 <<< Syntax Error
Response.Write "Test3"
End Select

As far as I can tell the syntax *is* correct. What am I missing?
You mean as far as you can tell, aside from the error message telling
you
that the syntax is not correct???

Yes that's exactly what I mean. Which is why I said it.

'As far as I can tell' means, I haven't found anything to say why it may
not
be syntactically correct.
I don't know why you're throwing "Is" in there, where did you find
syntax
that looked like that?

It's the VB syntax. When '< 0' didn't work, I wondered if the VB syntax
was
appropriate.
Here is the documentation for select case:
http://msdn.microsoft.com/library/en...71eefb3b01.asp

Which I'd already reviewed of course... It's a bit sparse, and only
indicates the obvious - that '< 0' or 'Is <0' does not qualify as a valid
expression.
Personally, I suggest using IF...ELSE...END IF for range vs. exact
value.

f1 = CSng(rs.fields("Field1"))
if f1 = 0 then
response.write "Test1"
elseif f1 < 0 then
response.write "Test2"
else
response.write "Test3"
end if

Of course, this route was always open to me, but I would have rather used
Select Case for clarity.

Elsewhere I have found a comment that '=' is the only comparison operator
allowed in VBScript Select Case statement, and this operator is implicit.

It's not entirely surprising, that VBScript has such shortcomings compared
to VB, but I expected the 'official' sources to make this clear.

CJM

I don't think the documentation is at fault here. There is no assumption in
the documentation that the reader is already familiar with VB thereby
needing guidance as to the differences. The standard definition of an
'expression' is assumed by the documentation. There is nothing there that
implies that the testexpression would form the first operand in any partial
expression in any Case expressionlist. The documentation is not being
'sparse' by not describing things you might think you can do but actually
can't, such documentation would be impossible to read.

Just my pennies worth ;)
Jul 3 '06 #11

P: n/a
CJM
The MSDN VB documentation states that 'Case <expressionlist-n>' is the
correct syntax. So does the MSDN VBScript documentation.

I made the incorrect assumption (or perhaps an expectation) that MSDN would
regard these as being the same, when they aren't.
Update: When I was complaining about the documentation being sparse, I've
just realised that most of the information is being hidden, since I was
viewing the page in Firefox. The basic syntax is shown but there are no
accompanying notes. In Opera 9, it doesnt shown anything. Check for
yourselves. [So I'm not going mad after all....]

Having now attempted to view the page in IE6, I can now see the comments
which does indicate that comma-separated expression are allowed...

However, we are back to the argument of the mean of the word 'expression'.
According to the MSDN VB documentation 'Is < 0' is a valid expression... so
why wouldn't it be valid for VBScript? Surely, the limits to the type of
acceptable expressions should be stated?

http://foldoc.org/foldoc.cgi?query=e...&action=Search

Jul 3 '06 #12

P: n/a
CJM wrote:
However, we are back to the argument of the mean of the
word 'expression'. According to the MSDN VB documentation
'Is < 0' is a valid expression... so why wouldn't it be
valid for VBScript?
For one thing, VB is not VBScript. And [IS] has a very specific purpose in
VBScript -- the comparison of *objects*:

http://msdn.microsoft.com/library/en...3fad510189.asp

Lastly, in VBScript, [IS] requires two operands. Your expression does not
satisfy this requirement.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jul 3 '06 #13

P: n/a
CJM

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:Os**************@TK2MSFTNGP03.phx.gbl...
>
For one thing, VB is not VBScript. And [IS] has a very specific purpose in
VBScript -- the comparison of *objects*:
Of course VB is not VBScript. I have never indicated anything to the
contrary, but they *are* closely related, so when I couldnt find the
information I wanted for VBScript, I looked for inspiration from VB.
Jul 3 '06 #14

P: n/a

CJM wrote:
"Dave Anderson" <NY**********@spammotel.comwrote in message
news:Os**************@TK2MSFTNGP03.phx.gbl...

For one thing, VB is not VBScript. And [IS] has a very specific purpose in
VBScript -- the comparison of *objects*:

Of course VB is not VBScript. I have never indicated anything to the
contrary, but they *are* closely related, so when I couldnt find the
information I wanted for VBScript, I looked for inspiration from VB.
Not always a bad idea, but given that it didn't work in this case, it
seems pretty pointless complaining that it didn't work, just as it's
pretty pointless complaining that any official documentation doesn't
explicity exclude all the infinite number of possiblities one could
come up with in terms of incorrect syntax.

--
Mike Brind

Jul 3 '06 #15

P: n/a
CJM wrote:
...when I couldnt find the information I wanted for VBScript...
I can certainly appreciate this statement. When looking for the [Select
Case] documentation, I found that it was not listed here...
http://msdn.microsoft.com/library/en...4cde3390cb.asp

....yet it is listed among the Statements in the left-pane menu. That's a bad
oversight, IMO.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jul 3 '06 #16

P: n/a

"CJM" <cj*******@newsgroup.nospamwrote in message
news:Oc**************@TK2MSFTNGP04.phx.gbl...
The MSDN VB documentation states that 'Case <expressionlist-n>' is the
correct syntax. So does the MSDN VBScript documentation.

I made the incorrect assumption (or perhaps an expectation) that MSDN
would
regard these as being the same, when they aren't.
Update: When I was complaining about the documentation being sparse, I've
just realised that most of the information is being hidden, since I was
viewing the page in Firefox. The basic syntax is shown but there are no
accompanying notes. In Opera 9, it doesnt shown anything. Check for
yourselves. [So I'm not going mad after all....]

Having now attempted to view the page in IE6, I can now see the comments
which does indicate that comma-separated expression are allowed...

However, we are back to the argument of the mean of the word 'expression'.
According to the MSDN VB documentation 'Is < 0' is a valid expression...
so
why wouldn't it be valid for VBScript? Surely, the limits to the type of
acceptable expressions should be stated?
The VB documentation very specifically highlights the special use of the
keyword 'Is' in the context of a Case statement. The VBScript documentation
does not. The VBScript documentation also omits reference to the 'To'
keyword in the context of the Case statement and of course trying to use it
also results in an error.
http://foldoc.org/foldoc.cgi?query=e...&action=Search

Jul 3 '06 #17

P: n/a
CJM

"Mike Brind" <pa*******@hotmail.comwrote in message
news:11**********************@v61g2000cwv.googlegr oups.com...
>
Not always a bad idea, but given that it didn't work in this case, it
seems pretty pointless complaining that it didn't work, just as it's
pretty pointless complaining that any official documentation doesn't
explicity exclude all the infinite number of possiblities one could
come up with in terms of incorrect syntax.
First of all, I'm not complaining it didn't work; I explicitly said that I
was hoping for inspiration from the VB documentation but that I accepted its
limitations.

Secondly, I expect reserved terms like 'expressionlist' to be consistent
across MSDN especially since the term 'expression' is not an MS-only term. I
don't expect MSDN to detail the infiinite number of terms of incorrect
syntax, but I would hope it would give a better indication of what is and
isn't allowed. The fact is that I wanted to use a valid expression in the
statement (an expression that MS regard as valid for VB) yet it isn't valid
for VBScript, and on top of that, the most important MSDN help was hidden
because of poor web design, so it was difficult to even infer the right
information. More importantly, I geniunely expected VBScript to be able to
handle this kind of expression, and I'm surprised it doesnt. And I'm
surprised I didnt find any 3rd-party websites that remarked on this
situation - I can't be the first person to hope for more out of the Select
Case statement.

What I would complain about (if it were any use) were the ratio of helpful
responses to those that weren't helpful (like yours). I didn't start this
thread to complain about VBScript - I wanted to find out an answer to
satisfy my curiousity. I eventually got that answer, but not before a number
of people tried to sour the thread with their unhelpful answers. If people
put the same amount of effort into helping posters rather than starting
conflict, this NG would be that much better.

The unintentional insight I gained was that the majority of users seem to be
locked into IE as their preferred UA (which surprised me).

CJM
Jul 4 '06 #18

P: n/a
CJM

"Dave Anderson" <NY**********@spammotel.comwrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
CJM wrote:
>...when I couldnt find the information I wanted for VBScript...

I can certainly appreciate this statement. When looking for the [Select
Case] documentation, I found that it was not listed here...
http://msdn.microsoft.com/library/en...4cde3390cb.asp

...yet it is listed among the Statements in the left-pane menu. That's a
bad oversight, IMO.

Dave,

Are you sure? It's listed for me (in both IE & FF). Right column, third from
bottom.

CJM
Jul 4 '06 #19

P: n/a

CJM wrote:
"Mike Brind" <pa*******@hotmail.comwrote in message
news:11**********************@v61g2000cwv.googlegr oups.com...
<snip>
>
What I would complain about (if it were any use) were the ratio of helpful
responses to those that weren't helpful (like yours). I didn't start this
thread to complain about VBScript - I wanted to find out an answer to
satisfy my curiousity. I eventually got that answer, but not before a number
of people tried to sour the thread with their unhelpful answers. If people
put the same amount of effort into helping posters rather than starting
conflict, this NG would be that much better.
I don't accept that as a true reflection of this group. Sometimes
people need the blindingly obvious to be explained, and some posters
will do so in a seemingly abrupt, possibly even a sarcastic way -
although it is impossible to read motivation into a few short words
most of the time.

IMO this NG suffers much less from people deliberately trying to flame
than any other I know of. It hardly ever happens, and I don't see that
it necessarily did in this thread. True, my contribution wasn't
helpful, and was probably better left unposted. If it irritated you, I
apologise.
>
The unintentional insight I gained was that the majority of users seem to be
locked into IE as their preferred UA (which surprised me).
I only use it to look at the online MSDN documentation. Their
silly-arse dhtml doesn't work in Firefox :-)

Nor, incidentally, does this page: http://www.aspfaq.com/categories.asp
.......

--
Mike Brind

Jul 4 '06 #20

P: n/a
CJM

"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@h44g2000cwa.googlegro ups.com...
>
I only use it to look at the online MSDN documentation. Their
silly-arse dhtml doesn't work in Firefox :-)
You should try it with Opera. Seriously...
Nor, incidentally, does this page: http://www.aspfaq.com/categories.asp
......
Hmmm... the internal category links don't work it appears...

I notice the Aaron is going through a major overhaul, so maybe we should
wait until it settles.

[Aaron: have you gone live yet? The start date was 18/06/06, but it doesn't
look like you've switched over yet]

CJM
Jul 4 '06 #21

P: n/a
CJM wrote:
"Mike Brind" <pa*******@hotmail.comwrote in message
news:11*********************@h44g2000cwa.googlegro ups.com...
>>
I only use it to look at the online MSDN documentation. Their
silly-arse dhtml doesn't work in Firefox :-)

You should try it with Opera. Seriously...
>Nor, incidentally, does this page:
http://www.aspfaq.com/categories.asp ......

Hmmm... the internal category links don't work it appears...

I notice the Aaron is going through a major overhaul, so maybe we
should wait until it settles.

[Aaron: have you gone live yet? The start date was 18/06/06, but it
doesn't look like you've switched over yet]
Aaron no longer owns the site, so don't blame him ...
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 4 '06 #22

P: n/a
CJM

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:eq**************@TK2MSFTNGP03.phx.gbl...
Aaron no longer owns the site, so don't blame him ...
--
He's still top of the Credits page, and the Copyright notice is still
against him...

Who is in charge these days?
Jul 4 '06 #23

P: n/a
CJM wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcomwrote in message
news:eq**************@TK2MSFTNGP03.phx.gbl...
>Aaron no longer owns the site, so don't blame him ...
--

He's still top of the Credits page, and the Copyright notice is still
against him...

Who is in charge these days?
I'll let him address this himself. I don't know the details.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 4 '06 #24

P: n/a
CJM wrote:
Are you sure? It's listed for me (in both IE & FF). Right column,
third from bottom.
I am no longer sure. I see it now, but looked for it three times yesterday
and did not see it.

[scratches head]

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Jul 4 '06 #25

P: n/a
I do not know what the holdup is on the new site; like you, I expected to
see it go live June 18th.

As for credits/copyright, well, technically, I still did write the majority
of the content, and put the site together. Just because I no longer run it
administratively does not mean that the content is suddenly credited to
someone else. Part of the deal was (a) all links from Google, etc. will
remain intact no matter what changes they make to the structure of the site,
and (b) I would maintain author credit.

So, some of the slowdown may be attributed to them keeping up their end of
the deal.
Who is in charge these days?
The name(s) of the actual people involved, I'm not at liberty to discuss,
and I don't know what you would get out of that information anyway. If you
have questions or feedback regarding the site, you can continue to use the
feedback page, just like you would have a month ago or 5 years ago. They
may respond slower than I typically did, they may respond faster, I really
don't know.
Jul 4 '06 #26

This discussion thread is closed

Replies have been disabled for this discussion.