Array as case statement?

arage

Registered User.
Local time
Today, 16:57
Joined
Dec 30, 2000
Messages
537
I was wondering could I use an array as the CASE in a CASE STATEMENT like below?

Code:
Select case array(I,J)
	Case (1,1)
	Case (1,2)
End select
 
You could, but I'm sure it won't return the kind of flow that you are looking for.

It would seem to me that you are trying to find when the indices, I & J,are pointing at certain nodes, not necessarily the value contained in the node. Perhaps:
Code:
Select Case I
    Case 1:  Select Case J
                 Case 1: 'For the (1,1) node
                 Case 2: 'For the (1,2) node
             End Select
     Case 2: Select Case J
                 Case 1: 'For the (2,1) node
            :
            :
            :

I guess it all depends on what you are looking for.
 
you’re right I’m using this code to refer to a node in order to fill it.

Bear with me I’m an array newbie but I defined my array something like this array(1 to 9, 1 to 2)
So this is a 9 row array with 2 columns right?

But based on your solution above, it seems a little different from what I’m thinking.

I specified letter I to refer to the rows & J for the columns, did I do something wrong?
 
No, you dimensioned your array correctly. But when the Select case array(I,J) statement is executed, it is going to be looking at the contents of the node at the current values of I and J. Depending on the datatype, that could have the value "Horse", or 54.85 or whatever.
Let's look at a checkerboard as a 8 x 8 array. Then we could populate by:

ckbd(1,1) = "WhiteRook"
ckbd(1,2) = "WhiteKnight"
ckbd(1,3) = "WhiteBishop"
ckbd(1,4) = "WhiteQueen"
ckbd(1,5) = "WhiteKing"
ckbd(1,6) = "WhiteBishop"
:
:
ckbd(7,7) = "BlackPawn"
ckbd(7,8) = "BlackPawn"
ckbd(8,1) = "BlackRook"
:
:

and so on.

To reference what the whole checkerboard looks like, we could do:
Code:
For I = 1 to 8
   For J = 1 to 8
       MsgBox "At space " & I & ", " & J & " is a " & ckbd(I,J)
   Next J
Next I

If you wanted to move the Pawn at 7,3 2 spaces ...
ckbd(5,3) = ckbd(7,3)
ckbd(7,3) = ""
HTH
 
Last edited:

Users who are viewing this thread

Back
Top Bottom