 |

06-02-2004, 02:50 PM
|
|
Centurion
|
|
Join Date: Jul 2001
Location: Victoria, Australia
Posts: 199
|
|
Select Case Statement
|
I want to use the select case method so as it triggers between to different values i.e. Case is greater than 6000 but less than say 7000.
Code:
select case variable
case > 6000 <7000 etc,etc.
What is the correct coding for this.
Dazza.
|
|

06-02-2004, 02:52 PM
|
 |
Sith Lord
Retired Leader * Expert *
|
|
Join Date: Feb 2004
Location: Monterrey, Mexico
Posts: 2,179
|
|
Code:
Select Case variable
Case 6000 to 6999
'.
'.
'.
End Select
EDIT: Change to 7000 --> to 6999
|
|

06-02-2004, 02:52 PM
|
|
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Posts: 1,300
|
|
|
try this
Case 6001 To 6999
thingimijig.
|
|

06-02-2004, 02:53 PM
|
|
Centurion
|
|
Join Date: Jul 2001
Location: Victoria, Australia
Posts: 199
|
|
Quote:
|
Originally Posted by thingimijig
try this
Case 6001 To 6999
thingimijig.
|
Thank You....
Regards Dazza.
|
|

06-02-2004, 03:10 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
|
What do you do if it is between 2 values?
(ie: looking for letters A-Z and a-z(not specific))
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-02-2004, 03:17 PM
|
|
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Posts: 1,300
|
|
it is case sensitive, so you can do this
Code:
Select Case Text1.Text
Case "b" To "d"
MsgBox "letter from b to d"
End Select
or
Code:
Select Case Text1.Text
Case "B" To "D"
MsgBox "letter from B to D"
End Select
or both.
Code:
Select Case Text1.Text
Case "B" To "D", "b" To "d"
MsgBox "either"
End Select
thingimijig.
|
|

06-02-2004, 03:23 PM
|
 |
Sith Lord
Retired Leader * Expert *
|
|
Join Date: Feb 2004
Location: Monterrey, Mexico
Posts: 2,179
|
|
Or this
Code:
Select Case UCase(Text1.Text)
Case "B" To "D"
MsgBox "founded"
End Select
|
|

06-02-2004, 03:29 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
Looking for the "," thing over there between the two statements, not the code (it was just an example  ). Thanks.
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-02-2004, 03:30 PM
|
 |
Retread
Retired Moderator * Expert *
|
|
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,742
|
|
|
Just to specify, thingimijig's code is best if you want it to be CaSe-SeNsAtIvE, while rick's is better for if you want it to be case-insensative.
|
|

06-02-2004, 03:32 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
|
What happens when you do use ">" and "<" in a case statement. VB doesn't reject it, yet it doesn't work. Why?
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-02-2004, 03:54 PM
|
|
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Posts: 1,300
|
|
they can be used like so.
Code:
Select Case Val(Text1.Text)
Case Is < 200, Is > 400
MsgBox "value is either lower than 200 or greater than 400"
End Select
you can also get the same results with.
Code:
Select Case Val(Text1.Text)
Case 200 To 400
Case Else
MsgBox "value is either lower than 200 or greater than 400"
End Select
thingimijig.
|
|

06-02-2004, 03:56 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
Yet the compiler accepts it like this, but it doesn't act like above(with comma):
Code:
Case Is > 100 < 150
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-02-2004, 05:24 PM
|
 |
Joseph Koss
* Guru *
|
|
Join Date: Aug 2003
Location: Unfashionable End
Posts: 3,615
|
|
|
This last one looks to me like it may not be performing as expected (ie, like the others)
.... Case Is > 100 < 150
I believe this will probably be evaluated like this:
.... Case Is > (100 < 150)
Which is the same as:
... Case Is > -1
Someone else can check this.. because I just dont see the value in this sort of syntax anyways.
|
|

06-02-2004, 05:31 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
Makes sense. I tried these two statements to see if it as you said:
Code:
'Will work if Case > -1
Case Is > 10 < 100
'Will fire if Case < -1
Case Is < 10 > 100
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-02-2004, 09:42 PM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
|
|
|
Actually (10 > 100) is false (0) so I would expect the second one to fire if the value
was less than 0.
Case Is < 10 < 100 (10 < 100) is True (-1)
so would fire for less than -1
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

06-02-2004, 10:12 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
|
Your right in the first part(I meant it to be <=).
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-02-2004, 10:19 PM
|
 |
Centurion
|
|
Join Date: Apr 2004
Location: New York City
Posts: 174
|
|
So now we have this:
Code:
'Will work if Case > -1
Case Is > 10 < 100
'Will work if Case < -1
Case Is < 10 < 100
'Will Work if Case > 0
Case Is > 10 > 100
'Will Work if Case < 0
Case Is < 10 > 100
|
__________________
"If a little knowledge is dangerous, where is a man who has so much as to be out of danger?" -Thomas Huxley
|

06-03-2004, 05:54 AM
|
 |
Sinecure Expert
Super Moderator * Guru *
|
|
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,722
|
|
Yes, that compiles and executes, but there is little reason to express cases in that manner, since it would tend to mislead someone as to what it is doing.
Boolean Values (True and False) are represented internally in Visual Basic as a two byte integer.
True = -1
False = 0
In practice, any non-zero value is interpreted by Visual Basic as True, but the results
of a comparison (i.e. x < y, or x = y) will always return -1 (True) or 0 (False) depending
on whether the condition is True or False.
So if I had the code,
Dim i as Integer
i = 10 < 100 '10 is less than 100 so i is set to -1 (True)
Debug.Print i ' Would print -1
So your select block is essentially saying (perhaps a bit clearer).
Code:
'Will work if Case > -1
Case Is > True
'Will work if Case < -1
Case Is < True
'Will Work if Case > 0
Case Is > False
'Will Work if Case < 0
Case Is < False
'Or
'Will work if Case > -1
Case Is > -1
'Will work if Case < -1
Case Is < -1
'Will Work if Case > 0
Case Is > 0
'Will Work if Case < 0
Case Is < 0
|
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
|

06-16-2004, 11:49 AM
|
|
Freshman
|
|
Join Date: Jul 2003
Posts: 32
|
|
Code:
Dim QM As String
Dim LM As String
Dim SRT As String
Dim SWT As String
Dim WH As String
Dim ShtDwn As String
'Load From Registry
GetKeyValue HKEY_CURRENT_USER, "Software\WaTimer", "QuietMode", QM
GetKeyValue HKEY_CURRENT_USER, "Software\WaTimer", "LoudMode", LM
GetKeyValue HKEY_CURRENT_USER, "Software\WaTimer", "Remain", SRT
GetKeyValue HKEY_CURRENT_USER, "Software\WaTimer", "WakeTime", SWT
GetKeyValue HKEY_CURRENT_USER, "Software\WaTimer", "WindowHeight", WH
GetKeyValue HKEY_CURRENT_USER, "Software\WaTimer", "ShtDwn", ShtDwn
Select Case Not "" ' [b]<--- There is the problem[/b]
Case QM
txt_SleepMode.Text = QM
Case LM
txt_WakeUpMode.Text = LM
Case SRT
txt_SetRemainTime.Text = SRT
Case SWT
txt_SetWakeTime.Text = SWT
Case WH
Me.Height = WH
Case ShtDwn
pn_ShtDwn.Value = ShtDwn
End Select
My Problem is when there is no RegValue(s) the Variable(s) are = "". Now I only want to change the object if the value not "". But
Select Case Not ""
Select Case <> ""
won't work.
Is there any way to do that or do I have to make a workaround?
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|