Parameter to have leading and ending zeros

Parameter to have leading and ending zeros

jletcher
Advisor Advisor
2,328 Views
9 Replies
Message 1 of 10

Parameter to have leading and ending zeros

jletcher
Advisor
Advisor

I have a client that wants the part number to be driven by size with a catch.

 

Hope I can explain it for all to understand. I have it some what working but need some guidance.

 

The part number goes like this:

 

625A3-A01.000M0.500 or 625A3-A10.000M1.000

 

625A3 = Profile Threaded or unthreaded rod

 

A= material type A-Mild Steel, B-Ground and polish rod, C-Stainless steel and so on

 

01.000 is the Length of the part (this is an issue will explain at bottom)

 

M= thread code  K-no tapping, L-10-32 UNC, M-1/4-20 UNC, N- 5/16-18 and so on

 

.500= Diameter of rod ( nothing bigger than 9 inches)

 

Ok I have everything working but the Length the issue with this is the leading and trailing zeros and extra..

 

If the length is 1/2 inch the number needs to show as 00.5000 if it is 1 inch needs to show as 01.000 if it was 10 inches it needs to show like 10.000.

 

Now this is the problem I am having if it is 1/2 I get this 0.500 but I need that extra 0 in the front like 00.500.

I am also having issues when the number is 4 inches or a rounded number 10,9,5 no matter if I have the parameter set to show trailing zeros it seems to work and not work so I get 4 and not 4.000 even in this I would have to get ilogic to add a zero to it like 04.000.

 

How can I get ilogic to look at the number of characters in the Length and if it is less than the what I need add the others.

 

Hope I explained it for all to understand. If not ask away and I will try to expain more.

 

Here is what I have been trying but I am failing.

 

If LENGTH >= Len(5) Then
	Parameter("L_1") = "0" & LENGTH & ".000"
Else
	Parameter("L_1") = LENGTH
End If


iProperties.Value("Project", "Part Number")= "625A3-" & Mat_Code & L_1 & Tap_Code & Rod

 

0 Likes
Accepted solutions (1)
2,329 Views
9 Replies
Replies (9)
Message 2 of 10

jletcher
Advisor
Advisor

I added this to try to get the trailing zeros to show but still no luck.

 

Parameter("L_1") = "0" & Round(LENGTH,3)

 

0 Likes
Message 3 of 10

jletcher
Advisor
Advisor

Hello, is there any body out there........ Pink floyd Smiley Happy

0 Likes
Message 4 of 10

Curtis_W
Consultant
Consultant
Accepted solution

Hi jletcher,

 

Assuming this is being done via ilogic, you can use something along these lines:

 

iLogicOption DoubleForEquals Off
sL_1 = Format(L_1, "00.000")
sRod = Format(Rod, "00.000")
iProperties.Value("Project", "Part Number") = "625A3-" & Mat_Code & sL_1 & Tap_Code & sRod

see this link for more on the VB Format function:

http://msdn.microsoft.com/en-US/library/59bz1f0h%28v=vs.80%29.aspx

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 EESignature

Message 5 of 10

jletcher
Advisor
Advisor

Curtis I swear you are thee MAN.......

 

Smiley Happy

 

Thank you so much. I never thought of using the same thing I use in excel..

 

 

 

 

0 Likes
Message 6 of 10

Anonymous
Not applicable

I have a problem ?

 

my value is 0,0125 and when is rounding becoming at 0,012 but not true?

the good result for me is 0,013

this is my rule

 

CODE =  0,0125

CODE2 = Round(CODE,3)

 

Thamks for your help

 

 

 
0 Likes
Message 7 of 10

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

I'm quite sure that this is because of the underlying .NET behaviour. You can read about that on various sites:

http://stackoverflow.com/questions/977796/why-does-math-round2-5-return-2-instead-of-3-in-c

 

So you could use the .NET function directly to round away from zero instead of to even:

MsgBox(Math.Round(0.0125, 3, MidpointRounding.AwayFromZero))

 

This will give you 0.013

 

Cheers,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 8 of 10

Anonymous
Not applicable

thanks you for your help Adam, i try that 🙂

0 Likes
Message 9 of 10

Anonymous
Not applicable

all the time 0,013 now 😞 with any number???

0 Likes
Message 10 of 10

jdkriek
Advisor
Advisor

sergelachance, you might want to start a new thread - I have a feeling you have other conditions in your code.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes