Results 1 to 6 of 6

Thread: problems with CASE

  1. #1
    dgr
    Guest

    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

  2. #2
    joan_fl
    Guest
    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. Select Case varsquare
    2.    Case 0
    3.     'do something
    4.    Case 1
    5.     'do something
    6.    Case 2
    7.     'do something
    8.    Case 3
    9.     'do something
    10.    Case 4
    11.     'do something
    12.    Case 5
    13.     'do something
    14.    Case 6
    15.     'do something
    16.    Case 7
    17.     'do something
    18.    Case 8
    19.     'do something
    20. End Select
    21.  
    22. 'You can also group them together if you wish
    23.   Select Case varsquare
    24.      Case 0, 4, 6, 8
    25.      'do something
    26.   End Select
    27.  
    28. 'You can concantenate selections
    29.     Select Case varsquare
    30.       Case 0 To 4
    31.     End Select
    Hope this helps.

  4. #4
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    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.


  5. #5
    Addicted Member
    Join Date
    Feb 2002
    Location
    Belgium
    Posts
    190
    i expected problems in this Case

  6. #6
    joan_fl
    Guest
    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
  •  



Click Here to Expand Forum to Full Width