|
-
Apr 16th, 2002, 01:39 PM
#1
problems with CASE
hi
i have quite a few case statements to write, I know its possible to do it with a loop but the point of the excercise is for me to learn CASE....
there is an array of variables, "varsquare" that goes from 0 to 8, thats 9 elements. Each element can take the values "human" or "computer" or ""
I wish to create a set of case statements that
Select Case varsquare
Case varsquare(0) = "human" and Case varsquare(1) = "human" and Case varsquare(2) = "" then do this
Case varsquare(3) = "human" and Case varsquare(4) = "human" and Case varsquare(5) = "" then do this
etc
Case Else then do this
End Select
Anyone know how it is possible to use an array in a case statement?
cheers
dgr
-
Apr 16th, 2002, 01:44 PM
#2
Try something like this:
Select Case varsquare
Case varsquare(0) = "human" AND varsquare(1) = "human" AND varsquare(2) = ""
Case varsquare(3) = "human" AND varsquare(4) = "human" AND varsquare(5) = ""
Case Else
End Select
Remeber though the differences between AND, OR
-
Apr 16th, 2002, 01:46 PM
#3
VB Code:
Select Case varsquare
Case 0
'do something
Case 1
'do something
Case 2
'do something
Case 3
'do something
Case 4
'do something
Case 5
'do something
Case 6
'do something
Case 7
'do something
Case 8
'do something
End Select
'You can also group them together if you wish
Select Case varsquare
Case 0, 4, 6, 8
'do something
End Select
'You can concantenate selections
Select Case varsquare
Case 0 To 4
End Select
Hope this helps.
-
Apr 16th, 2002, 01:49 PM
#4
Not NoteMe
I don't think what you want to do is possible with a select case, as you can only look at one value, not an array.
Correct me if i'm wrong anyone though, as i would be interested if you can.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Apr 16th, 2002, 01:56 PM
#5
Addicted Member
i expected problems in this Case
-
Apr 16th, 2002, 01:59 PM
#6
I thought if you could make the expression in an If statement, you can make the expression in a Case statement.
Apparently this is NOT true... Try this.
Dim iNumber As Integer
iNumber = 2
Select Case iNumber
Case (iNumber = 1) Or (iNumber = 2)
Debug.Print "1 or 2"
Case iNumber = 2 Or iNumber = 3
Debug.Print "2 or 3"
End Select
Doesnt work as expected... Sorry for the missinformation.
Joan
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
|