What's wrong with this Select Case Syntax?

P

Penny

Hi all,

My browser throws this Select Case block back at me pointing out a syntax
error on the line: 'Case < 251', between the word 'Case' and the '<' symbol.

***************************

intWeightTotal = 550

Select Case intWeightTotal
Case < 251
' Do something
Case < 501
' Do something
Case < 1001
' Do something
Case < 2001
' Do something
Case Else
' Do something else
End Select

**************************

All my other Select Case blocks work fine without the '<' symbol.

I've also tried the line 'Case Is < 251' but same error.

Any ideas?

Regards

Penny.
 
R

Roland Hall

: Hi all,
:
: My browser throws this Select Case block back at me pointing out a syntax
: error on the line: 'Case < 251', between the word 'Case' and the '<'
symbol.
:
: ***************************
:
: intWeightTotal = 550
:
: Select Case intWeightTotal
: Case < 251
: ' Do something
: Case < 501
: ' Do something
: Case < 1001
: ' Do something
: Case < 2001
: ' Do something
: Case Else
: ' Do something else
: End Select
:
: **************************
:
: All my other Select Case blocks work fine without the '<' symbol.
:
: I've also tried the line 'Case Is < 251' but same error.
:
: Any ideas?

Try this:

Select Case True
Case intWeightTotal < 251
' Do something
Case intWeightTotal < 501
' Do something
Case intWeightTotal < 1001
' Do something
Case intWeightTotal < 2001
' Do something
Case Else
' Do something else
End Select

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
P

Penny

Thanks Roland,

It now works with your code tip.

All the documentation I could find told me to do it the original way I tried
which is a bit frustrating.

Thanks again!

Regards

Penny.
 
R

Roland Hall

in message : Thanks Roland,
:
: It now works with your code tip.
:
: All the documentation I could find told me to do it the original way I
tried
: which is a bit frustrating.
:
: Thanks again!

You're welcome. I hear ya'. I remember searching quite awhile for this
once myself.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bob Barrows [MVP]

Penny said:
Hi all,

My browser throws this Select Case block back at me pointing out a
syntax error on the line: 'Case < 251', between the word 'Case' and
the '<' symbol.

That's VB/VBA syntax that does not work in vbscript. It's just one of the
many differences that can be found between the two languages. Unfortunately,
not all these differences are well-documented; however, this one is ...
somewhat. You have to read this article:

Visual Basic for Applications Features Not In VBScript
http://msdn.microsoft.com/library/en-us/script56/html/vsgrpNonFeatures.asp


Where you'll find this text in the "Select Case" row:
Expressions containing _Is_ keyword or any comparison operators
Expressions containing a range of values using the To keyword.

Roland already showed you the usual workaround so I won't repeat it here.

You can download an installable version of te WSH documentaion here:
http://tinyurl.com/7rk6

Bob Barrows
 
R

Roland Hall

in message
: It's really weird too because this code definetly works and it does not
: mention the variable in each case
: I have used case statements like in this example for many years now
:
: http://www.powerasp.com/content/code-snippets/asp-randomizer.asp

Kyle...

I don't think that's a true comparison to her issue. She's working with
ranges.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
K

Kyle Peterson

you sir are correct
it is different

seems the the variable is needed when using "<" and what not
 
R

Roland Hall

: you sir are correct
: it is different
:
: seems the the variable is needed when using "<" and what not

I guess we'll never know why MSFT made it different. It sure adds to the
confusion.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top