Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Conversion from string to type 'Double" is not valid

blucas0325
Contributor

Conversion from string to type 'Double" is not valid

blucas0325
Contributor
Contributor

I have an iLogic Rule that is tied to a Custom "Form" assembly. This has been working for year but recently we upgraded to Inventor 2023 and I am now getting an error when I try to use it. 

 

I am getting a "Conversion from string "value" to type 'Double' is not valid" error message. I have done some searching and it sounds like I need to incorporate a "CDbl()" but I am not familiar enough with this to know how it should be setup.

 

Here is my iLogic rule:

 

LENGTH = RoundToFraction(Length_ID, 1 / 16, RoundingMethod.Round)
WIDTH = RoundToFraction(Width_ID, 1/16, RoundingMethod.Round)
DEPTH = RoundToFraction(Height_ID, 1/16, RoundingMethod.Round)
L = RoundToFraction(LENGTH, 1/16, RoundingMethod.Round)
W = RoundToFraction(WIDTH, 1/16, RoundingMethod.Round)
D = RoundToFraction(DEPTH, 1/16, RoundingMethod.Round)
iProperties.Value("Custom", "Item #")=ITEMNUMBER

iProperties.Value("Project", "Description")=NAME & "," & " " & L & " X " & W & " X " & D
iProperties.Value("Custom", "EXPORT")=PARTNUMBERorPKGNUMBER
iProperties.Value("Summary", "Title") = NAME
iProperties.Value("Custom", "DESIGN STATUS") = DESIGN_STATUS
iProperties.Value("Custom", "CUSTPN") = CUSTPN
iProperties.Value("Custom", "PKG") = PKG

 Could someone give me a hand and point me in the right direction?

 

Thank you in advance!

0 Likes
Reply
Accepted solutions (1)
1,904 Views
11 Replies
Replies (11)

abdullah_elq
Advocate
Advocate
Which line of code does your error pop-up mention?
0 Likes

blucas0325
Contributor
Contributor

Line 1 & Line 2

0 Likes

blucas0325
Contributor
Contributor
@abdullah_elq it is line 1 & 2
0 Likes

Frederick_Law
Mentor
Mentor

What is the  value of Length_ID and Width_ID?

Program could fail if they're empty or not numeric.

0 Likes

blucas0325
Contributor
Contributor

@Frederick_Law the values will be in decimal form. Below is a screenshot of the Form dialog window that we use to input the values.

 

blucas0325_0-1689798005655.png

 

0 Likes

abdullah_elq
Advocate
Advocate
Try this:
LENGTH = RoundToFraction(CDbl(Length_ID), 1 / 16, RoundingMethod.Round)

0 Likes

blucas0325
Contributor
Contributor

@abdullah_elq - that didn't work. Got the same error message. Below is a screenshot of the error message tabs.

 

blucas0325_0-1689799460145.pngblucas0325_1-1689799555691.png

 

0 Likes

Frederick_Law
Mentor
Mentor

It cannot convert fraction string to number.

0 Likes

Curtis_Waguespack
Consultant
Consultant

Hi @blucas0325 

 

Maybe something like this.

 

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

 

 

imports System.Text.RegularExpressions
wholeNum = CDec(Math.Truncate(Length_ID))
decNum = Length_ID - wholeNum
fraction = RoundToFraction(decNum, 1 / 16, RoundingMethod.Round)

'convert rounded fraction back to decimal
Dim div = Regex.Replace(fraction, "(\d+)/(\d+)", Function(m) Decimal.Parse(m.Groups(1).Value / Decimal.Parse(m.Groups(2).Value)))
	
LENGTH = wholeNum + div
L = RoundToFraction(LENGTH, 1 / 16, RoundingMethod.Round)

msgbox(L)

 

0 Likes

Frederick_Law
Mentor
Mentor
Accepted solution
LENGTH = Length_ID - (Length_ID MOD 0.0625)

 

blucas0325
Contributor
Contributor

@Frederick_Law That worked! Thank you!

0 Likes