Do Loop to check multiple values and return a single result...maybe

Do Loop to check multiple values and return a single result...maybe

jfenter
Enthusiast Enthusiast
465 Views
5 Replies
Message 1 of 6

Do Loop to check multiple values and return a single result...maybe

jfenter
Enthusiast
Enthusiast

Through a series of rules, I am creating iProperties to show whether a certain condition exists or not.  Each of these properties will either end with a value of "Yes" or "No".

 

iProperties.Value("Custom", "Width Configured?")
iProperties.Value("Custom", "Honeycomb Configured?")
iProperties.Value("Custom", "Inner Rail 1 Configured?")
iProperties.Value("Custom", "Inner Rail 2 Configured?")

I would like to create a rule to check the values of these 4 properties and perform one of two operations given the values of those properties.

 

If any one of the 4 iproperties = "No" Then
	iLogicVb.RunRule("Width Check")
	iLogicVb.RunRule("Panel Length - No Rails")
ElseIf ALL 4 properites = "Yes" Then
        'MessageBox.Show("Part is properly configured.  No changes needed.", "Limit Check")
End If

I assume I need to run a Do Loop to check the values of the properties and return one of the two outcomes I have shown above.  If so, I don't know how to write the code.  If there is another way, which way is it?

0 Likes
466 Views
5 Replies
Replies (5)
Message 2 of 6

JhoelForshav
Mentor
Mentor

Hi @jfenter 

 

This would be a very simple solution for your problem 🙂

 

Dim oCount As Integer = 0
If iProperties.Value("Custom", "Width Configured?") Then oCount += 1
If iProperties.Value("Custom", "Honeycomb Configured?") Then oCount += 1
If iProperties.Value("Custom", "Inner Rail 1 Configured?") Then oCount += 1
If iProperties.Value("Custom", "Inner Rail 2 Configured?") Then oCount +=1

If oCount < 4
	iLogicVb.RunRule("Width Check")
	iLogicVb.RunRule("Panel Length - No Rails")
Else
        MessageBox.Show("Part is properly configured.  No changes needed.", "Limit Check")
End If
Message 3 of 6

tdant
Collaborator
Collaborator

I don't think that will work, because the values of the iProperties will be Strings, and iLogic doesn't implicitly convert strings to boolean. You could change the other rules to make the values of your iProperties either "True" or "False", or you could use the below code to evaluate the current values:

If LCase(iProperties.Value("Custom", "Width Configured?")) = "no" Or _
		LCase(iProperties.Value("Custom", "Honeycomb Configured?")) = "no" Or _
		LCase(iProperties.Value("Custom", "Inner Rail 1 Configured?")) = "no" Or _
		LCase(iProperties.Value("Custom", "Inner Rail 2 Configured?")) = "no" Then
	iLogicVb.RunRule("Width Check")
	iLogicVb.RunRule("Panel Length - No Rails")
Else
        MessageBox.Show("Part is properly configured.  No changes needed.", "Limit Check")
End If
0 Likes
Message 4 of 6

JhoelForshav
Mentor
Mentor

 

I dont see any reason not to use Yes/No-properties for this purpose.

0 Likes
Message 5 of 6

jfenter
Enthusiast
Enthusiast

My initial test of the suggested solution seems to be working, but I found an error in the rules that set the iProperties that is causing a "no" result when it should be a "yes".  Unfortunately I've been forced into temporarily changing projects so I have to sit on this until I can continue debugging the rules.

0 Likes
Message 6 of 6

J-Camper
Advisor
Advisor

This is another way to do it:

Sub Main
	Dim StringList As String() ={"Width Configured?", "Honeycomb Configured?", "Inner Rail 1 Configured?", "Inner Rail 2 Configured?"} '{"Test", "This"}
	
	If CheckThese(StringList) = False
		MessageBox.Show("Part is not properly configured.  Running rules now.", "Failed Limit Check")
'		iLogicVb.RunRule("Width Check")
'		iLogicVb.RunRule("Panel Length - No Rails")
	Else
		MessageBox.Show("Part is properly configured.  No changes needed.", "Passed Limit Check")
	End If
	
End Sub

Private Function CheckThese(oStrings As String()) As Boolean
	Dim i As Integer = 0
	While i < oStrings.Count
		Result = False
		Try
			prop = iProperties.Value("Custom", oStrings(i))
		Catch
			MessageBox.Show("The iProperty: [ " & oStrings(i) & " ] is missing from this part!", "Missing iProperty")
		    Result = False
			Exit While
		End Try
		If iProperties.Value("Custom", oStrings(i)) = True Then Result = True Else Exit While 
		i=i+1
	End While
	Return Result
End Function

It does the checking in a Private function, that returns to your main rule As a Boolean response.  It is set up so you can check any number of Yes/No iProperties, and returns a False Boolean at the first False value found.  It also handles missing iProperties by prompting the missing property name before returning a False Boolean.

 

 

0 Likes