Case statement with a range of integers 
Author Message
 Case statement with a range of integers

How can a range of values be tested in a case statement, for example:

case mvarTestInteger
    case between 1 and 5
        ' some code

    case else
        ' some code

end select

I'm getting an error message that only >= etc can be used, rather than
between.  The only option I've thought of is a series of if then else
statements, but this is not as clean as a case statement.

Bill



Tue, 24 Aug 2004 02:35:10 GMT  
 Case statement with a range of integers

Quote:
> case mvarTestInteger
     case 1 to 5
>         ' some code

>     case else
>         ' some code

> end select

D.


Quote:
> How can a range of values be tested in a case statement, for example:

> case mvarTestInteger
>     case between 1 and 5
>         ' some code

>     case else
>         ' some code

> end select

> I'm getting an error message that only >= etc can be used, rather than
> between.  The only option I've thought of is a series of if then else
> statements, but this is not as clean as a case statement.

> Bill



Tue, 24 Aug 2004 03:32:11 GMT  
 Case statement with a range of integers

Quote:
> I'm getting an error message that only >= etc can be used, rather than
> between.  The only option I've thought of is a series of if then else
> statements, but this is not as clean as a case statement.

Why are you "thinking up" options at all? Put your text cursor anywhere
within or next to the keywords "Select Case" that you have typed in the code
window and press F1. The help files cover what you asked about and *more*.
According to the times of your post and dnagel's answer, it took you nearly
an hour to get the same answer you could have gotten for yourself, within
seconds, from VB's help files. Seems to me like an inefficient use of your
time.

Rick



Tue, 24 Aug 2004 06:33:11 GMT  
 Case statement with a range of integers


Quote:
> > I'm getting an error message that only >= etc can be used, rather than
> > between.  The only option I've thought of is a series of if then else
> > statements, but this is not as clean as a case statement.

> Why are you "thinking up" options at all? Put your text cursor anywhere
> within or next to the keywords "Select Case" that you have typed in the
code
> window and press F1. The help files cover what you asked about and *more*.
> According to the times of your post and dnagel's answer, it took you
nearly
> an hour to get the same answer you could have gotten for yourself, within
> seconds, from VB's help files. Seems to me like an inefficient use of your
> time.

While I don't disagree at all with you in that using VB's Help should be the
very first choice......that was kinda cruel... albeit a practicle example of
wasted time.  <g>  But....sometimes, that's what it takes to make the point.

Mike



Tue, 24 Aug 2004 13:43:00 GMT  
 Case statement with a range of integers
Cruel? Maybe... if so, my apologies to Bill. I wasn't going for cruel; I was going for
incredulous. I had such trouble believing that a question whose answer was so readily
available in the help files was being asked, that I guess I went into "near obnoxious"
mode <g>.

From my standpoint, all I saw was "I've heard of this VB command and I *kind of thought it
should work this way. It didn't. Why?" While I'll be the first to admit that VB's help
files are quite poor index-wise, it is quite rich in information.  It often amazes me that
a user won't at least *try* the help files first, before posting a question to a
newsgroup.

Rick

Quote:
> > > I'm getting an error message that only >= etc can be used, rather than
> > > between.  The only option I've thought of is a series of if then else
> > > statements, but this is not as clean as a case statement.

> > Why are you "thinking up" options at all? Put your text cursor anywhere
> > within or next to the keywords "Select Case" that you have typed in the
> code
> > window and press F1. The help files cover what you asked about and *more*.
> > According to the times of your post and dnagel's answer, it took you
> nearly
> > an hour to get the same answer you could have gotten for yourself, within
> > seconds, from VB's help files. Seems to me like an inefficient use of your
> > time.

> While I don't disagree at all with you in that using VB's Help should be the
> very first choice......that was kinda cruel... albeit a practicle example of
> wasted time.  <g>  But....sometimes, that's what it takes to make the point.

> Mike



Tue, 24 Aug 2004 22:25:58 GMT  
 Case statement with a range of integers
Case 1,2,3,4,5 works


Quote:
> How can a range of values be tested in a case statement, for example:

> case mvarTestInteger
>     case between 1 and 5
>         ' some code

>     case else
>         ' some code

> end select

> I'm getting an error message that only >= etc can be used, rather than
> between.  The only option I've thought of is a series of if then else
> statements, but this is not as clean as a case statement.

> Bill



Wed, 25 Aug 2004 01:35:20 GMT  
 Case statement with a range of integers
Hi Steve:

Quote:
> Case 1,2,3,4,5 works

or simply...

   Case 1 To 5

Doug.



Wed, 25 Aug 2004 02:40:46 GMT  
 Case statement with a range of integers
Since I'm the original "culprit" here I thought I should respond.  Yes I
should have read the help file before asking for help, but I also have found
the VB help files pretty hard to use.  In any event, I'll try to use them
whenever possible, and I do appreciate the response of all, even Rick.

Bill


Quote:
> How can a range of values be tested in a case statement, for example:

> case mvarTestInteger
>     case between 1 and 5
>         ' some code

>     case else
>         ' some code

> end select

> I'm getting an error message that only >= etc can be used, rather than
> between.  The only option I've thought of is a series of if then else
> statements, but this is not as clean as a case statement.

> Bill



Wed, 25 Aug 2004 08:43:53 GMT  
 Case statement with a range of integers
As I indicated in my post, I'll be one of the first to admit that VB's help files can be
somewhat inhospitable; however, in this case, you would have been pleasantly surprised had
you tried. In the future, you (and anyone else out there like Bill) should try the help
files first. Then, if you can't find what you are looking for, post to this or one of the
other VB newsgroups. Just tells us that you tried to use the help files first, but to no
avail and I, or someone else, will then be happy to try and help you. I just want to know
that the finding the answer to your question is as important to you as you are asking it
to become to those of us who volunteer here.

Rick


Quote:
> Since I'm the original "culprit" here I thought I should respond.  Yes I
> should have read the help file before asking for help, but I also have found
> the VB help files pretty hard to use.  In any event, I'll try to use them
> whenever possible, and I do appreciate the response of all, even Rick.

> Bill



> > How can a range of values be tested in a case statement, for example:

> > case mvarTestInteger
> >     case between 1 and 5
> >         ' some code

> >     case else
> >         ' some code

> > end select

> > I'm getting an error message that only >= etc can be used, rather than
> > between.  The only option I've thought of is a series of if then else
> > statements, but this is not as clean as a case statement.

> > Bill



Wed, 25 Aug 2004 12:23:54 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Select Case & Integer Comparisons

2. .Range.Case constants

3. Select Case range

4. SQL Statement - Too Few Parameters - Integer problem

5. Case Statement with combo box

6. Array as case statement?

7. Select Case Statement Help

8. Case statement syntax

9. Case statements?

10. Select Case Statement

11. Criteria for select case statements

12. Embedded or nested Select Case statements

 

 
Powered by phpBB® Forum Software