Hi All,

I'm interested in obtaining a block of vb code that would take two measured points (or a number of measured points) and produce a difference result that could then be used itself in a max/min math formula. For example: two points along the X-axis: one measures -1.5" and the other +2.0. The vb would produce a usable item valued at 3.5" in a max/min calculation consisting of other results obtained in the same manner. Ultimately, I would desire to discover the max difference set among all the sets.

I'm just beginning vb code, so any examples would definitely be appreciated.

-John

## Min/ Max difference formula for measured point sets

### Re: Min/ Max difference formula for measured point sets

I have a solution to sort through CLoud data and find highest Z points. The same sorting could be done for High and Low points. See details here - viewtopic.php?f=30&t=84#p4605

- Ryan Christopher
- Nikon
**Posts:**229**Joined:**Mon Jun 06, 2011 3:00 pm**Location:**Sumner Washington-
**Contact:**

### Re: Min/ Max difference formula for measured point sets

Hi John,

You would have to change the GetReportInfo line but this may do what you want.

===================================================

Dim i

Dim k

Dim p(1 to 4)

Dim out

for i = 1 to 4

p(i) = GetReportInfo("POINT" & i, "3D", 3)

next i

for k = 1 to 3

if abs(p(k)) > abs(p(k+1)) then

p(k+1) = abs(p(k))

else

p(k+1) = abs(p(k+1))

end if

next k

out = p(k)

===================================================

You would have to change the GetReportInfo line but this may do what you want.

===================================================

Dim i

Dim k

Dim p(1 to 4)

Dim out

for i = 1 to 4

p(i) = GetReportInfo("POINT" & i, "3D", 3)

next i

for k = 1 to 3

if abs(p(k)) > abs(p(k+1)) then

p(k+1) = abs(p(k))

else

p(k+1) = abs(p(k+1))

end if

next k

out = p(k)

===================================================

- Ryan Christopher
- Nikon
**Posts:**229**Joined:**Mon Jun 06, 2011 3:00 pm**Location:**Sumner Washington-
**Contact:**

### Re: Min/ Max difference formula for measured point sets

Oops...here is a better version that lets you do your inputs outside of the logic.

================================================================

'FIND MAX T DEV OF POINT GROUP

''''''declaration of variables: paste this block only once in your cmm-m program

Dim i

Dim p(1 to 200)

Dim out

Dim StartPt

Dim EndPtA

Dim EndPtB

Dim NamePrefix

Dim NameSuffix

'FIND MAX T DEV OF POINT GROUP

''''''instantiate the variables below for each block of points

StartPt = 1

EndPtA = 189

NamePrefix = "POINT"

NameSuffix = ""

''''''extraction of T deviation value from cmm-m

for i = StartPt to EndPtA

p(i) = GetReportInfo(NamePrefix & i & NameSuffix, "T", 3)

next i

'''''calculation of largest T deviation

EndPtB = EndPtA - 1

for i = StartPt to EndPtB

if abs(p(i)) > abs(p(i+1)) then

p(i+1) = abs(p(i))

else

p(i+1) = abs(p(i+1))

end if

next i

'''''assignment of largest T deviation to a variable

out = p(i)

================================================================

================================================================

'FIND MAX T DEV OF POINT GROUP

''''''declaration of variables: paste this block only once in your cmm-m program

Dim i

Dim p(1 to 200)

Dim out

Dim StartPt

Dim EndPtA

Dim EndPtB

Dim NamePrefix

Dim NameSuffix

'FIND MAX T DEV OF POINT GROUP

''''''instantiate the variables below for each block of points

StartPt = 1

EndPtA = 189

NamePrefix = "POINT"

NameSuffix = ""

''''''extraction of T deviation value from cmm-m

for i = StartPt to EndPtA

p(i) = GetReportInfo(NamePrefix & i & NameSuffix, "T", 3)

next i

'''''calculation of largest T deviation

EndPtB = EndPtA - 1

for i = StartPt to EndPtB

if abs(p(i)) > abs(p(i+1)) then

p(i+1) = abs(p(i))

else

p(i+1) = abs(p(i+1))

end if

next i

'''''assignment of largest T deviation to a variable

out = p(i)

================================================================

- medupriest
- Moderator
**Posts:**408**Joined:**Fri Mar 13, 2015 11:59 am

### Re: Min/ Max difference formula for measured point sets

This can be done without VB scripting or with VB scripting. The non-VB route is easier of course.

non-VB:

From the code, you can see that each point is evaluated, and if the new value is > the current "MaxX" then the the variable "MaxX" gets replaces tih that value. If you want to look for the point with the smallest value, you just change the ">" to "<".

If you would like to see the values, just remove the apostrophe from the beginning of the "MsgBox" lines.

You can then use a math function in a script to assign the value you are looking for to another variable and that variable can be reported as a User Defined Dimension.

non-VB:

- Measure the series of points as a cloud

- Do a two point construction looking for High/Low points from a cloud (this will take some strategy in finding features or machine axis that are furthers/closest to the points you want)

- report the distance between the two constructed points

- First we need to figure out how many cloud points we are going to evaluate. We can count points in a cloud with this script

Code: Select all

```
'Count Points in Cloud
NumPnts = GetFeaturePropertyAct("CLOUD1", 1)
'MsgBox(NumPnts)
```

- Next we need to look at each point in turn and see what is the furthest (in this case) point in X. This will involve a loop that will evaluate each point in the cloud by using the variable "NumPoints"

Code: Select all

```
MaxX = -10000
Dim Xpoint(1500)
'Loop Through All points in Cloud
For i = 1 to NumPnts
Xpoint(i) = GetCloudPointPropertyAct("CLOUD1", i , 1)
If Xpoint(i) > MaxX Then
MaxX = Xpoint(i)
End If
Next
'MsgBox(MaxX)
```

From the code, you can see that each point is evaluated, and if the new value is > the current "MaxX" then the the variable "MaxX" gets replaces tih that value. If you want to look for the point with the smallest value, you just change the ">" to "<".

If you would like to see the values, just remove the apostrophe from the beginning of the "MsgBox" lines.

You can then use a math function in a script to assign the value you are looking for to another variable and that variable can be reported as a User Defined Dimension.

- medupriest
- Moderator
**Posts:**408**Joined:**Fri Mar 13, 2015 11:59 am

### Re: Min/ Max difference formula for measured point sets

Also, Ryan's response is awesome as always.