×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Remove Leading Zeroes in Parameter (Knowledge Reaction)

Remove Leading Zeroes in Parameter (Knowledge Reaction)

Remove Leading Zeroes in Parameter (Knowledge Reaction)

(OP)
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.

RE: Remove Leading Zeroes in Parameter (Knowledge Reaction)

i ll get another look later but the VBA Format function does not work for you?

Eric N.
indocti discant et ament meminisse periti

RE: Remove Leading Zeroes in Parameter (Knowledge Reaction)

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources