Select Case based on 2 booleans

Select Case based on 2 booleans

mat_hijs
Collaborator Collaborator
1,373 Views
4 Replies
Message 1 of 5

Select Case based on 2 booleans

mat_hijs
Collaborator
Collaborator

I'm trying to write a Select Case statement in iLogic that's based on 2 True/False parameters. I just tried to write it out as my human brain would process it, but who would have known computers think differently? Is there a way to do this cleanly, or am I best off just using a bunch of If/ElseIf statements?

 

Here's what I tried to do:

Select Case Boolean1 And Boolean2
	Case True And True
		MsgBox("True+True")
	Case True And False
		MsgBox("True+False")
	Case False And True
		MsgBox("False+True")
	Case False And False
		MsgBox("False+False")
End Select

0 Likes
Accepted solutions (2)
1,374 Views
4 Replies
Replies (4)
Message 2 of 5

FINET_Laurent
Advisor
Advisor
Accepted solution

Hi,

 

I whould do something like this :

 

Dim oString As String = Param1 & Param2

Select Case oString
	
Case "TrueTrue"
	MsgBox("TrueTrue")
	
Case "TrueFalse"
	MsgBox("TrueFalse")
	
Case "FalseTrue"
	MsgBox("FalseTrue")
	
Case "FalseFalse"
	MsgBox("FalseFalse")
	
End Select

 Regards,

 

FINET L.

If this post solved your question, please kindly mark it as "Solution"

If this post helped out in any way to solve your question, please drop a "Like"

@LinkedIn     @JohnCockerill

0 Likes
Message 3 of 5

JelteDeJong
Mentor
Mentor
Accepted solution

you select statment rewritten comes down to this:

If (Boolean1 And Boolean2) = (True And True) Then
	MsgBox("True+True")
ElseIf (Boolean1 And Boolean2) = (True And False) Then
	MsgBox("True+False")
ElseIf (Boolean1 And Boolean2) = (False And True) Then
	MsgBox("False+True")
ElseIf (Boolean1 And Boolean2) = (False And False) Then
	MsgBox("False+False")
End If

this is probably not what you wanted.  I would go for this:

If (Boolean1) Then
	If (Boolean2) Then 
		MsgBox("True+True")		
	Else
		MsgBox("True+False")
	End If
Else
	If (Boolean2) Then
		MsgBox("False+True")
	Else
		MsgBox("False+False")
	End If
End If 

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 5

mat_hijs
Collaborator
Collaborator

Both these solutions would probably work perfectly, but after googling about vb.net a bit I found another solution which makes it very visual to see what's going on for a non programmer like me.

This is the solution I got:

Select Case True
	Case Boolean1 = True And Boolean2 = True
		MsgBox("True+True")
	Case Boolean1 = True And Boolean2 = False
		MsgBox("True+False")
	Case Boolean1 = False And Boolean2 = True
		MsgBox("False+True")
	Case Boolean1 = False And Boolean2 = False
		MsgBox("False+False")
End Select

Message 5 of 5

Z0methink
Enthusiast
Enthusiast
MsgBox(Param1 & Param2)
0 Likes