I'm trying to format a number with leading and trailing zeros. If I only needed trailing zeros I'd set the number as a parameter and force the formating there. I tried using the Format function but it fails and I found one other instance of someone trying it and it failing also.
For example I want to change 2.125 into 02.13
P.S.
Just for fun I went to the VBA editor and tried this.
debug.Print format(2.125,"00.00")
02.13
Works perfectly in the VBA but not in iLogic
Solved! Go to Solution.
Solved by ekinsb. Go to Solution.
Hi pball,
You can use this:
myNumber = format(2.125,"00.00") MessageBox.Show(myNumber, "iLogic")
Or just this:
MessageBox.Show(format(2.125,"00.00"), "iLogic")
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Hi pball,
Does adding a DoubleForEquals line help? :
iLogicOption DoubleForEquals Off myNumber = format(2.125,"00.00") MessageBox.Show(myNumber, "iLogic")
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
have you tried round?
MessageBox.Show(Round(2.125, 2),"iLogic")
or
MessageBox.Show(CStr(Format(2.125, "00.00")))
It looks like that for some reason your rule is picking up a different Format function. The Format function is a leftover from the older Visual Basic, but is still supported in VB.Net for backward compatibility. You can try specifying the complete namespace to the correct Format function. An alternative is to use the .Net ToString function to do the formatting. Both of these are demonstrated below.
Dim value As Double = 2.125 MessageBox.Show(Microsoft.VisualBasic.Strings.Format(value,"00.00"), "iLogic") MessageBox.Show(value.ToString("00.##"), "iLogic 2")
Deleted.
Edit:
Thanks for the two examples, they both work great and are better solution than my home made function I've been using.
Awakening this topic as it's the closest post to solving what I'm attempting to do. I too am trying to format text via iLogic while also concatenating other text to arrive at a lengthy and elaborate self-resolving part number. I need to utilize a specific amount of characters so I need to convert a number to include preceding zeros as space fillers. So for example if I have a value of "4" I need to convert to a text value of "004"; I do not currently have a need for a decimal value but wouldn't mind knowing how to apply one.
This post covers the concatenating method I am able to succeed with
Another post that comes close but doesn't work
Some attempts I've tried that have failed include:
SyntaxEditor Code Snippet
Test = Format%d(Width,"000")
Test = Format(Width,"000")
Test = value.ToString("000",Width)
@llorden4 wrote:
Awakening this topic as it's the closest post to solving what I'm attempting to do. I too am trying to format text via iLogic while also concatenating other text to arrive at a lengthy and elaborate self-resolving part number. I need to utilize a specific amount of characters so I need to convert a number to include preceding zeros as space fillers. So for example if I have a value of "4" I need to convert to a text value of "004"; I do not currently have a need for a decimal value but wouldn't mind knowing how to apply one.
This post covers the concatenating method I am able to succeed with
Another post that comes close but doesn't work
Some attempts I've tried that have failed include:
SyntaxEditor Code Snippet
Test = Format%d(Width,"000")
Test = Format(Width,"000")
Test = value.ToString("000",Width)
It's only after a post do you think of something. I was able to achieve my desired results by simply adding by the number of tenths for the desired number of placeholders, converting to a string, and then taking the Right value of the string by the number of desired places.
(Example: for 3 decimal places)
Test = Right(CStr(VALUE + 1000),3)
This works handily for my condition with no decimal values, would have to include multiple routines to include a decimal format in similar fashion. If anyone can provide an all inclusive "Format" option for iLogic I'd be all ears.
I know this is an old post, but I was trying to format a parameter as a string for use in an iProperty.
I had to use this method:
'Declare a shaft diameter single and capture the parameter value
Dim oShaftDiaSingle As Single = Parameter.Value("Shaft_Dia")
' Declare a shaft diameter string
Dim oShaftDia As String = Format(oShaftDiaSingle, "0.0000")
All other attempts to format the parameter were unsuccessful. For example, this would not work:
Dim oShaftDia as String = Parameter.Value("Shaft_Dia").ToString("0.0000")
Perhaps someone could explain why the "ToString" did not work.
Hope this is helpful to others.
Regards,
Jerry
@JBernsto avoid conversion errors, you have to assign a numeric Type as shown below
' First you have to assign a dataType/numericType
Dim oShaft As Single = Parameter.Value("Shaft_Dia")
' OR
' Dim oShaft As Double = Parameter.Value("Shaft_Dia")
MessageBox.Show(oShaft.ToString("0.0000"))
' OR
' MessageBox.Show(Format(oShaft,"0.0000"))