|
-
Feb 12th, 2004, 05:44 AM
#1
Thread Starter
Sleep mode
Is this really possible ?[Resolved]
I want to use Select Case in this way (evaluation two values at the same time) , is it legal (It works half way though )?
VB Code:
'Class member variables
Dim a As Integer
Dim b As Integer
'Inside a method .
Select Case a AndAlso b
Case a = 20, b = 40
Case a = 70, b = 30
Case a = 0, b = 1
End Select
Last edited by Pirate; Feb 12th, 2004 at 08:49 AM.
-
Feb 12th, 2004, 06:32 AM
#2
PowerPoster
Hi
I find that your code works all the time. Why do you say "Halfway"?
A shorter way would be
select case true
.................
Last edited by taxes; Feb 12th, 2004 at 08:02 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 07:51 AM
#3
Thread Starter
Sleep mode
I don't think it's going to solve the problem but how would you write the cases to evalutate two variables ?
-
Feb 12th, 2004, 08:08 AM
#4
PowerPoster
Hi,
After trying your code I edited my first reply just as you were posting.
If using Select Case True the leave the rest of your code as it was:
Select Case True
Case a = 20, b = 40
Case a = 70, b = 30
Case a = 0, b = 1
End Select
or
Select Case a AndAlso b
Case (a = 20, b = 40)
Case (a = 70, b = 30)
Case (a = 0, b = 1)
End Select
I have no problems with any of them
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 08:10 AM
#5
Originally posted by Pirate
I don't think it's going to solve the problem but how would you write the cases to evalutate two variables ?
VB Code:
Select Case True
Case a = 20 And b = 40
Case a = 70 And b = 30
Case a = 0 And b = 1
End Select
Does that work?
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Feb 12th, 2004, 08:17 AM
#6
PowerPoster
Hi,
On looking at MSDN AndAlso, I see that it states a boolean comparison is required, so may be it does not work consistently with non boolean variables, but I have not found that to be correct yet. If you have, post a sample, please.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 08:19 AM
#7
Thread Starter
Sleep mode
Cheers taxes , that works . 
Yes , crptcblade I used that and it works too.
-
Feb 12th, 2004, 08:24 AM
#8
PowerPoster
Hi crptcblade
Yes, although the code I posted was OR I have tried it with AND.
BUT see my last post and wait for Pirate's reply in case it is not consistent.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 08:27 AM
#9
PowerPoster
Hi Pirate,
REf. my first response to you.
"I find that your code works all the time. Why do you say "Halfway"?"
Any enlightenment? Bearing in mind my subsequent comments on the MSDN notes.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 08:28 AM
#10
Thread Starter
Sleep mode
It seems consistent after couple of testing .
-
Feb 12th, 2004, 08:42 AM
#11
Thread Starter
Sleep mode
Originally posted by taxes
Hi Pirate,
REf. my first response to you.
"I find that your code works all the time. Why do you say "Halfway"?"
Any enlightenment? Bearing in mind my subsequent comments on the MSDN notes.
For example :
When a = 0 and b =1
If I check this case like this
VB Code:
Select Case a AndAlso b
Case a = 0, b = 0
msgbox "first case"
Case a = 0, b = 1
msgbox "second case"
End Select
This would returns msgbox "first case" . Because it evaluates a as true and forget about the rest .
-
Feb 12th, 2004, 08:51 AM
#12
PowerPoster
Hi Pirate,
Of course it does,
the "," is an OR operator not an AND
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 08:57 AM
#13
Thread Starter
Sleep mode
Originally posted by taxes
Hi Pirate,
Of course it does,
the "," is an OR operator not an AND
Yes , it's true . But it's a bit confusing when I even tried this one and was the same result :
If clauses are usually better and safer but longer .
-
Feb 12th, 2004, 10:12 AM
#14
PowerPoster
Hi Pirate,
"Yes , it's true . But it's a bit confusing when I even tried this one and was the same result :
visual basic code:--------------------------------------------------------------------------------Case a = 0 AndAlso b = 1"
We are going round in ever decreasing circles here. The above works perfectly O.K. although it is unnecessarliy long. You must be doing something else wrong in your code. Are you declaring your variables in a location which make them invisible to your Select Case procedure/method?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 10:20 AM
#15
Thread Starter
Sleep mode
This is how I used it anyway . I set the variables a and b from different locations and I made sure have been set to different values every time .
VB Code:
Private a As Integer
Private b As Integer
Private Sub ValidateMe()
Select Case a AndAlso b
Case a = 0 And b = 0
MsgBox("index0 index0")
Case a = 0 And b = 1
MsgBox("index0 index1")
Case a = 0 And b = 2
MsgBox("index0 index2")
Case a = 1 And b = 0
MsgBox("index1 index0")
End Select
End Sub
Last edited by Pirate; Feb 12th, 2004 at 10:27 AM.
-
Feb 12th, 2004, 11:02 AM
#16
PowerPoster
Hi Pirate,
I think we are getting somewhere!
It is the use of "0" (zero) which is causing the problem. The programme is confusing it with Boolean. Change your checks for numbers 1 & 2 and it will work.
Man, I think we've both learned a bit here!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 12th, 2004, 11:31 AM
#17
Thread Starter
Sleep mode
Originally posted by taxes
Hi Pirate,
I think we are getting somewhere!
It is the use of "0" (zero) which is causing the problem. The programme is confusing it with Boolean. Change your checks for numbers 1 & 2 and it will work.
Man, I think we've both learned a bit here!
What if I want to check if these vars has 0s ? I mean , my implementation depends on these 0s .
-
Feb 12th, 2004, 11:42 AM
#18
PowerPoster
Hi,
Then you have to use the
Select Case True
Select Case True
Case (a = 0 And b = 0)
MsgBox("index0 index0")
Case (a = 1 And b = 2)
MsgBox("index1 index2")
Case (a = 0 And b = 2)
MsgBox("index0 index2")
Case (a = 1 And b = 0)
MsgBox("index1 index0")
End Select
It looks at though this is the reason for MSDN using the operator "AndAlso" as a Boolean.
After all that I reckon were are ahead of the field on this one!!
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|