Using the Select Case statement with an Array

SyntaxSocialist

Registered User.
Local time
Today, 19:24
Joined
Apr 18, 2013
Messages
109
Hi all. I have a boolean array, foundState(3), whose 4 elements correspond to 4 variables describing conditions that will dictate what action is taken upon closing a form.

There are only 6 possible outcomes for the array, and they can be divided into just 4 cases:

Case {T,T,T,T}

Case {T,T,T,F} OR {T,T,F,F} OR {T,T,F,T}

Case {T,F,F,F}

Case {F,F,F,F}

My problem is that I have no idea (and cannot find any information online) about what the proper syntax would be for this if I'm trying to create a "Select Case" statement for these 4 cases. Maybe this is something that can't be done. Any information, help, solutions, advice, or alternative methods would be greatly appreciated.

Thanks for stopping by.
 
Not sure that this is the most elegant way but...

Code:
Case Arr(0)="T" AND Arr(1)="T" AND Arr(2)="T" AND Arr(3)="T"

Case (Arr(0)="T" AND Arr(1)="T" AND Arr(2)="T" AND Arr(3)="F") OR _
    (Arr(0)="T" AND Arr(1)="T" AND Arr(2)="F" AND Arr(3)="F") OR _
    (Arr(0)="T" AND Arr(1)="T" AND Arr(2)="F" AND Arr(3)="T")

Case Arr(0)="T" AND Arr(1)="F" AND Arr(2)="F" AND Arr(3)="F"

Case Arr(0)="F" AND Arr(1)="F" AND Arr(2)="F" AND Arr(3)="F"
 
True and false have numeric values of -1 and 0 so you could add them

Select Case Arr(0)+Arr(1)+Arr(2)+Arr(3)
Case -4
Case -3
Case -1
Case 0
End Select
 
Last edited:
True and false have numeric values of 1 and 0 so you could add them

Select Case Arr(0)+Arr(1)+Arr(2)+Arr(3)
Case 4
Case 3
Case 1
Case 0
End Select

True is actually -1 so you would need to test for negative not positive.
You could also use the abs() function to return the absolute of the result.
Also this is assuming the OP is storing True and False as literals and not simply the letters "T" and "F".

[Edit]
Reread OP and realized it is a boolean array. So the first part of my post would be what you need.
 
True is actually -1 so you would need to test for negative not positive
Yes, you are right - I've corrected my post
Also this is assuming the OP is storing True and False as literals and not simply the letters "T" and "F".
The OP does say he is using an array of booleans, not text
 
True and false have numeric values of -1 and 0 so you could add them

Select Case Arr(0)+Arr(1)+Arr(2)+Arr(3)
Case -4
Case -3
Case -1
Case 0
End Select

Genius. Thanks for the idea! It wouldn't work in all cases, but since I want to perform the same action for both instances where foundState evaluates to -3, this should suit my purposes perfectly!

Will try it out and check back.
 
It wouldn't work in all cases
If it becomes the case then you do the following which will cater for all eventualities

Select Case -Arr(0)*1-Arr(1)*2-Arr(2)*4-Arr(3)*8

so for example
T,T,T,F=-1*1-1*2-1*4-0*8=7
T,T,F,F=-1*1-1*2-0*4-0*8=3
T,F,T,T=-1*1-0*2-1*4-1*8=13
etc

T,T,T,T would need to change from 4 to 15
Basic binary stuff!
 

Users who are viewing this thread

Back
Top Bottom