Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Conversion from string to type 'Double' is not valid

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
4901 Views, 5 Replies

Conversion from string to type 'Double' is not valid

I have declared some variables as inventor parameters like so:

Dim OffsetLeft As Inventor.Parameter = oParams.Item("offsetleft")
Dim OffsetRight As Inventor.Parameter = oParams.Item("offsetright")
Dim ISX As Inventor.Parameter = oParams.Item("isx)

 

Then a little later I use them in this equation, which is where I get the error "Conversion from string "17.5 mm" to type 'Double' is not valid.

ISX.Expression = (CaseWidth - OffsetLeft.Expression - OffsetRight.Expression - 4) / BayNumberX

17.5 mm being the value of OffsetLeft and OffsetRight. The other parameters are numerical User Parameters.

 

Do I need to convert OffsetLeft and OffsetRight to numerical values? If so, how do I do it?

5 REPLIES 5
Message 2 of 6
HermJan.Otterman
in reply to: Anonymous

I think you should use OffsetLeft.Value instead of OffsetLeft.expression.

mind the unit, VB works in cm

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 6
pball
in reply to: Anonymous

Yes you need to convert those values to a numeric type of Double. After you remove the mm or any other non-numeric part of your string you should be able to use CDbl(expression) to convert it to Double.
Message 4 of 6
Sharon_Menachery_782W9QAH4BU8
in reply to: Anonymous

Even I am getting the same error: "conversion from string to type, double is not valid" with the below code, when I am trying input anything other than numbers. Please could someone help me in solving this error.

Dim list As New ArrayList                       										
list = MultiValue.List("Part_Name")                      										
Dim msgl As String = vbCrLf & vbCrLf  										
For Each sVal As String In list                                         										
        msgl += sVal & vbCrLf                                         										
                                                        										
Next                                           										                                                       										
Dim val As String = InputBox("Enter new member name" & msgl, "Adding Val to List", New_Part_name)
If val = 0 Or val Is Nothing Then Exit Sub 
                                                										                                              										
                                                 										                                           										
If list.Contains(val) = False Then list.Add(val)                                                										
                                                                										
MultiValue.List("Part_Name") = list      		
Message 5 of 6

Hi @Sharon_Menachery_782W9QAH4BU8.  What is the purpose of your code example?  I assume it is throwing the error for Line 9, where you are first attempting to check the value of a String type variable against a numeric zero, which will not work.  In that case, it is either attempting to convert a String into an Integer (or similar numeric data Type), or trying to convert the numeric data Type to a String, before it can do the comparison.  If the zero had quotes around it, then it might have worked OK, but not with a raw numerical value.  Checking a String against 'Nothing' is OK, and will work, but is not typical.  The most common way to check if the value you get back from an InputBox is to check against an empty String ("").  We can also use the String.Empty property the same way.  However, there is also another vb.net tool that we can use in cases when the String may actually be 'Null' instead of simply empty.  String.IsNullOrEmpty(), then there is the constant vbNullString.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6


@Sharon_Menachery_782W9QAH4BU8 wrote:
Dim val As String = InputBox("Enter new member name" & msgl, "Adding Val to List", New_Part_name)		

Side-note, it's not considered good practice to name your own variables identical to existing operators/functions (VAL).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report