Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Remove Leading Zeroes in Parameter (Knowledge Reaction)

Status
Not open for further replies.

solid7

Mechanical
Jun 7, 2005
1,403
0
0
US
It's the end of the day, and my eyes are exhausted. Just need someone to push me through this one...

I've got a KBE reaction that fires a VB action to convert a parameter to a string, and shortens it to two decimal places. The only problem is, I need to also remove the leading zero, IF the number is less than one.

Code:
Dim inPart as Part
Set inPart = GetPart(parameter)

Dim retThickness As Double
retThickness = inPart.Parameters.GetItem("Thickness").Value / 25.4

retThickness = Round(retThickness, 5)

Dim strThickness As String

If InStr(retThickness, ".") > 0 Then
    If Len(Right(retThickness, Len(retThickness) - InStr(retThickness, "."))) >1 Then
        strThickness = Left(retThickness, InStr(retThickness, ".") + 2) + 0.01
    Else
        strThickness = (retThickness)
    End If
Else
    strThickness = retThickness
End If


If InStr(strThickness, ".") = 0 Then
    strThickness = strThickness & ".0"
End If

inPart.Parameters.GetItem("ThicknessStr").Value = strThickness

End Sub

Function GetPart(inElement as Object) as Part
    Dim holder As Object
    Dim i as Integer

    Set holder = inElement.Parent

    i = 0
    Do While i = 0
        If TypeName(holder) = "Part" Then
            Set GetPart = holder
            Exit Function
        ElseIf TypeName(holder) = "Application" Then
            Set GetPart = Nothing
            Exit Function
        End If
    
        Set holder = holder.Parent
    Loop    	
End Function

Clearly, I need another line of code in there to analyze everything to the left of the decimal point. I know this is easy, but I'm just too tired to see it. Your help is appreciated.

 
Replies continue below

Recommended for you

This is a KBE reaction, and it is part of a system that works very well. Just need this one little piece of info.

 
Status
Not open for further replies.
Back
Top