iLogic (Input String was Not in a Correct Format)

iLogic (Input String was Not in a Correct Format)

aboykin4DAV8
Explorer Explorer
159 Views
0 Replies
Message 1 of 1

iLogic (Input String was Not in a Correct Format)

aboykin4DAV8
Explorer
Explorer

Good Afternoon,

 

I am working on creating custom user parameters and iProperties for our part templates.  The idea is to build a rule that will create parameters/iProperties if they don't exist, then allow for user inputs on the form.  Inputs will be filled in directly, or from a predefined dropdown list with data from Excel.

 

Everything is working fine within the template without any error, but when I attempt to copy the Rule and Form into an existing part, I receive an error for my "Labor_Ops" parameter stating that the "Input string was not in a correct format" in the following line.

 

	rowFound = GoExcel.FindRow(excelFilePath, sheetName, "Labor_Ops", "=", Labor_Ops)

 

The values have been setup as "Text" in both Excel and Inventor prior to running this section of the rule.  Oddly enough if I open the rule in my new part, click "Save and Run", the rule processes as intended without error and the form works perfectly.

 

I can't post all of the code, but attached are some snippets showing the sections that would possibly be causing an error.  (Note: They are part of 2 different sub routines housed within a single Main routine).

 

Try
    ' Attempt to access an existing parameter
	Dim Labor_Ops_Variable As Inventor.Parameter = ThisDoc.Document.ComponentDefinition.Parameters.Item("Labor_Ops")
    ' If successful, do something with the parameter
	'Enter user defined iProperty
		customPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
	
		iProperties.Value("Custom", "Labor_Ops") = Parameter("Labor_Ops")
	'Uncomment line below for test
    'MessageBox.Show("Parameter 'Labor_Ops' found with value: " & Labor_Ops_Variable.Value)

Catch
    ' If the parameter doesn't exist, create it
	Dim userParameters As UserParameters = ThisDoc.Document.ComponentDefinition.Parameters.UserParameters
	Dim newParameter As Inventor.Parameter = userParameters.AddByValue("Labor_Ops", "Saw", UnitsTypeEnum.kTextUnits)
	
	'Uncomment line below for test
    'MessageBox.Show("Parameter 'Labor_Ops' created.")
End Try
	


-----------------------------------------------------------------
' Specify your Excel file path and sheet name
    Dim excelFilePath As String = "File Path Removed for Privacy"
    Dim sheetName As String = "Inventor Form Layout"

    ' Open the Excel file
    GoExcel.Open(excelFilePath, sheetName)
	
	Dim rangeArray As Object = GoExcel.NamedRangeValue("Labor_Ops")
	
	    ' Create a list to hold the values from the Excel column
    Dim oList As ArrayList = New ArrayList()


    ' Iterate through the Excel data (assuming a single column, e.g., Column A)
    ' For each row in the rangeArray
    For iRow = rangeArray.GetLowerBound(0) To rangeArray.GetUpperBound(0)
        ' Get the value from the current row and specific column (e.g., column index 0)
		Dim cellValue As Object = rangeArray(iRow, 0) ' 0 for the first column

        ' Check if the cell is not empty before adding to the list
        If Not IsNothing(cellValue) AndAlso cellValue.ToString().Trim() <> "" Then
            oList.Add(cellValue.ToString()) ' Add the string value to the list
        End If
    Next
	
	    ' Assign the populated list to the multi-value parameter (e.g., "MyParam")
    MultiValue.List("Labor_Ops") = oList
	
	rowFound = GoExcel.FindRow(excelFilePath, sheetName, "Labor_Ops", "=", Labor_Ops)
	
	If rowFound <> -1 Then
    ' If a row is found, get the value from the "Description" column of that row
    routersValue = GoExcel.CurrentRowValue("Routers")
	'Uncomment 3 lines below to test if form is working
    'MessageBox.Show("Routers: " & routersValue)
	'Else
    'MessageBox.Show("Labor_Ops not found.")
	End If
	
	'Assigns the found cell value to the "Router_Export" parameter
	Router_Export = routersValue

	
	    ' Close the Excel file
    GoExcel.Close()

 

 

 

 

0 Likes
160 Views
0 Replies
Replies (0)