Ilogic Error: Input string was not in a correct format

Ilogic Error: Input string was not in a correct format

Dartherick
Contributor Contributor
1,693 Views
4 Replies
Message 1 of 5

Ilogic Error: Input string was not in a correct format

Dartherick
Contributor
Contributor

Hello everyone,

 

I am trying to learn how to use "GoExcel" in inventor and every time I run the code, I get the following error message "Input string was not in a correct format". I am using Inventor Professional 2018.

 

Here is the code:

 

Dim File As String = "C:\Users\Dartherick\Downloads\Practice\Pipe Size\Pipe Size.xlsx"
GoExcel.Open(File, "Sheet1")
GoExcel.FindRow(File, "Sheet1", "Pipe Size", "=", PipeSize, "SCH", "=", SCH)
OD = GoExcel.CurrentRowValue("OD")
ID = GoExcel.CurrentRowValue("ID")
GoExcel.Close

 

 

Here is the content of the excel file:

Pipe SizeSCHIDOD
3/8"400.4930.675
3/8"800.4230.675
1/2"400.6220.840
1/2"800.5460.840
3/4"400.8241.050
3/4"800.7421.050
1"401.0491.315
1"800.9571.315
1"1600.8151.315

 

I think it would be helpful to specify that this table starts in the A1 cell and the name of the sheet is "Sheet1".

 

Any help would be much appreciated!

Thanks.

0 Likes
Accepted solutions (1)
1,694 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

There is still something that is unknown to us.  In your FindRow line of code, you are using two unquoted words.  I assume those are the names of local parameters, right?  If so, are those parameters numerical (units set to Inches, or similar), or are they text type user parameters (units set to Text)?  When working with cells in Excel, the cells can contain many different types of data, so the cell's value is returned as a generic Object.  Due to this, you often have to be absolutely sure about the data types you are dealing with, to make sure they are compatible.  The error message indicates that it may be trying to convert between a String (text) and a Double (numbers with decimal places).  You may have to include something in your code to compensate for or convert one data type to the other data type before they can be correctly compared.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Dartherick
Contributor
Contributor

Hi Wesley Crihfield,

 

The parameters are "Text" type, as it can be seen in the following image:

1075188_0-1634048341609.png

 

The "Pipe Size" & "SCH" columns are Text type, so the parameters and the excel columns have the same type of content.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

OK.  I saved your Excel file locally, created a new part document with an extruded pipe section, using your same parameter names, then added the same two text type parameters, all with the same values as are shown in your posted image of your parameters dialog box.  Then I copies your rule to it and changed the path to the file.  When I ran the rule, it seemed to work as expected.  It changed the values of the OD & ID parameters from .675 & .493 to .622 & .84. 

 

But I'm using Inventor Pro 2022.1.1, so it may be something that they have 'fixed' since the 2018 release.  Maybe it wasn't dealing with unit types as nicely back then or something, I'm not sure.

Maybe try incorporating the simple data type conversion tools into your code to see if it makes any difference.

Dim File As String = "C:\Users\Dartherick\Downloads\Practice\Pipe Size\Pipe Size.xlsx"
GoExcel.Open(File, "Sheet1")
GoExcel.FindRow(File, "Sheet1", "Pipe Size", "=", CStr(PipeSize), "SCH", "=", CStr(SCH))
OD = CDbl(GoExcel.CurrentRowValue("OD"))
ID = CDbl(GoExcel.CurrentRowValue("ID"))
GoExcel.Close

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 5

Dartherick
Contributor
Contributor
Thank you Wesley.

I changed the code with all the feedbacks that you gave me and now is working great.
0 Likes