Alright, my misstake, here's the corrected code with some more descriptions, so you could learn from it.
First of I have put the main part of the rule in the sub routine "Main". It's required by iLogic when you want to split your code to more parts (sub routines and functions) and it has to be called "Main" so iLogic know it has to be executed when the rule starts.
Sub routine is a part of code that will execute before the code goes to another line.
Function does the same, except it also returns a value.
I hope it's clear enough, ask if you need futher explenation.
Sub Main()
' Here I'm adding all measurements using the new sub routine called "AddMeasurement"
AddMeasurement("Work Plane22", "Work Plane12") ' Left rail and single rail
AddMeasurement("Work Plane23", "Work Plane13") ' Right rail and single rail
AddMeasurement("Work Plane22", "Work Plane20") ' Left rail and double rail
AddMeasurement("Work Plane23", "Work Plane21") ' Right rail and double rail
AddMeasurement("Work Plane13", "Work Plane20") ' Single rail and double rail
Dim HoneyCombMin As Double = 230 ' Definine the value for comparison
' Here I'm defining a text variable with no value
Dim MOL As String = vbnullstring
' Loop throught all measurements stored in the "MyDist" variable array
For i = 0 To MyDist.Lenght - 1 'Go through each measurement
' If the value in the array is bigger or equal to HoneyCombMin skipp this value
If MyDist(i) >= HoneyCombMin Then Continue For
' If the variable "MOL" isn't empty add a new row to it, so the new value goes there
If MOL <> vbnullstring Then MOL = MOL & vbnewline
' Add the value to the "MOL" variable along with some text
MOL = MOL & "Value Nr." & i + 1 & " (" & MyDist(i) & ") is less than " & HoneyCombMin
Next
' If the "MOL" variable is not empty show a message with it's content
If MOL <> vbnullstring Then MsgBox(MOL) 'Show the results (if any)
End Sub
' The definition of "MyDist" variable of the type "Double" = number with decimals
' The zero defines this variable as array with one "slot", as the counting starts from zero
Private MyDist(0) As Double 'Local variable to store the measurements
' The definition of the sub routine "AddMeasurement".
' In the brackets are required input values.
' "As String" means the accepted values must be text
Private Sub AddMeasurement(WorkPlaneA As String, WorkPlaneB As String)
' If the variable "MyDist" is not empty we need to add another "slot"
If Not MyDist(MyDist.Lenght - 1) = Nothing Then
' Since the lenght is 1 and the counting starts from 0, the value will grow by 1
ReDim Preserve MyDist(MyDist.Lenght)
End If
' Store the measurement in the last slot. Number of slots - 1 (counting starts from zero)
MyDist(MyDist.Lenght - 1) = Measure.MinimumDistance(WorkPlaneA, WorkPlaneB)
End Sub ' The end of the sub routine
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods