Home > Archive > ASP > July 2006 > Select Case
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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
| |
| Aaron Bertrand [SQL Server MVP] 2006-06-30, 6:55 pm |
| > 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/e...871eefb3b01.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
| |
|
|
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:e1zyqLFnGHA.4348@TK2MSFTNGP02.phx.gbl...
>
> 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/e...871eefb3b01.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
| |
| Evertjan. 2006-06-30, 6:55 pm |
| 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)
| |
| Aaron Bertrand [SQL Server MVP] 2006-06-30, 6:55 pm |
| > '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. ;-)
| |
|
|
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:uSrdtrFnGHA.4448@TK2MSFTNGP04.phx.gbl...
>
>
> 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....
| |
| Dave Anderson 2006-06-30, 6:55 pm |
| 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.
| |
| Aaron Bertrand [SQL Server MVP] 2006-06-30, 6:55 pm |
| > 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
| |
| Bob Lehmann 2006-06-30, 9:55 pm |
| >> Which I'd already reviewed of course... It's a bit sparse, and only
[color=darkred]
So, the documentation indicates the obvious, but it's not clear???
Bob Lehmann
"CJM" <cjmnews04@newsgroup.nospam> wrote in message
news:Od$ODcFnGHA.4212@TK2MSFTNGP04.phx.gbl...[color=darkred]
>
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in
message
> news:e1zyqLFnGHA.4348@TK2MSFTNGP02.phx.gbl...
you[color=darkred]
>
> 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.
>
syntax[color=darkred]
>
> It's the VB syntax. When '< 0' didn't work, I wondered if the VB syntax
was
> appropriate.
>
http://msdn.microsoft.com/library/e...871eefb3b01.asp[color=darkred]
>
> 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.
>
value.[color=darkred]
>
> 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
>
>
| |
| Dave Anderson 2006-07-01, 6:55 pm |
| 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.
| |
| Anthony Jones 2006-07-03, 3:55 am |
|
"CJM" <cjmnews04@newsgroup.nospam> wrote in message
news:Od$ODcFnGHA.4212@TK2MSFTNGP04.phx.gbl...
>
> "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in
message
> news:e1zyqLFnGHA.4348@TK2MSFTNGP02.phx.gbl...
you[color=darkred]
>
> 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.
>
syntax[color=darkred]
>
> It's the VB syntax. When '< 0' didn't work, I wondered if the VB syntax
was
> appropriate.
>
http://msdn.microsoft.com/library/e...871eefb3b01.asp[color=darkred]
>
> 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.
>
value.[color=darkred]
>
> 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 ;)
| |
|
| 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=...n&action=Search
| |
| Dave Anderson 2006-07-03, 7:55 am |
| 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/e...d3fad510189.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.
| |
|
|
"Dave Anderson" <NYRUMTPELVWH@spammotel.com> wrote in message
news:OsPLRdqnGHA.4728@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.
| |
| Dave Anderson 2006-07-03, 6:55 pm |
| 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/e...74cde3390cb.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.
| |
| Anthony Jones 2006-07-03, 6:55 pm |
|
"CJM" <cjmnews04@newsgroup.nospam> wrote in message
news:OctOBLqnGHA.4104@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=...n&action=Search
>
>
>
| |
| Mike Brind 2006-07-03, 6:55 pm |
|
CJM wrote:
> "Dave Anderson" <NYRUMTPELVWH@spammotel.com> wrote in message
> news:OsPLRdqnGHA.4728@TK2MSFTNGP03.phx.gbl...
>
> 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
| |
|
|
"Mike Brind" <paxtonend@hotmail.com> wrote in message
news:1151943208.475996.152390@v61g2000cwv.googlegroups.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
| |
|
|
"Dave Anderson" <NYRUMTPELVWH@spammotel.com> wrote in message
news:ecixc2rnGHA.1244@TK2MSFTNGP05.phx.gbl...
> CJM wrote:
>
> 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/e...74cde3390cb.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
| |
| Mike Brind 2006-07-04, 3:55 am |
|
CJM wrote:
> "Mike Brind" <paxtonend@hotmail.com> wrote in message
> news:1151943208.475996.152390@v61g2000cwv.googlegroups.com...
<snip>
[color=darkred]
>
> 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
| |
|
|
"Mike Brind" <paxtonend@hotmail.com> wrote in message
news:1152003118.527059.30530@h44g2000cwa.googlegroups.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
|
|
|
|
|