Get index of item in list of element

Get index of item in list of element

filippo.costantin3HZMT
Advocate Advocate
1,123 Views
5 Replies
Message 1 of 6

Get index of item in list of element

filippo.costantin3HZMT
Advocate
Advocate

Hi everyone, 

 

I need to read a coloumn of Excel file and create a list of element. I need to check if there is a value in this list and get the index of this list. 

2.PNG

For example, I have a For Cycle. In this Cycle is obtain a "Value". 

If this "Value" = "OM_L01_Pannello_Lamiera_Template" I want to get "Index"=1.

 

How can I do it?

 

If you have different solution this is good. 

 

I try to use :

VPanelTemplate = "OM_L01_Pannello_Lamiera_template"

'create list of element of coloumn A in image
Dim PartList As New List(Of String) 
PartList = GoExcel.CellValues(SharedVariable("MapExcelFilePath"), "02_Main Part", "A1", "A10")
	
For Each element In PartList
If element = VPanelTemplate Then
contatore=PartList.IndexOf(element)
Logger.Info("°°Questo è l'indice corretto= " & contatore & "°°")
End If	
Next

It doesn't run correctly. 

 

How can I solve it?

 

Thanks

0 Likes
Accepted solutions (1)
1,124 Views
5 Replies
Replies (5)
Message 2 of 6

snappyjazz
Collaborator
Collaborator

Hello @filippo.costantin3HZMT 

 

on the line: PartList = GoExcel.CellValues(SharedVariable("MapExcelFilePath"), "02_Main Part", "A1", "A10")

 

try: PartList.AddRange(GoExcel.CellValues(SharedVariable("MapExcelFilePath"), "02_Main Part", "A1", "A10"))

0 Likes
Message 3 of 6

filippo.costantin3HZMT
Advocate
Advocate

thanks for your answer, but it doesn't run. 

 

Have you got other solution?

 

Thanks

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor
Accepted solution

You need to change the Type of PartList from List(Of String) to ArrayList.  The function specifies that it's resulting object is an "IList", which is a 'non-generic' collection.  A 'non-generic' collection is one that can hold multiple Types of objects, like the ArrayList.  The List(Of String) is a 'generic' collection...it can only hold one Type of object.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

filippo.costantin3HZMT
Advocate
Advocate

Thanks a lot. It run. 

Where can I find a guide to use the List of object and Array in ilogic?

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor

Since iLogic is an Inventor Add-in, and it uses VB.NET as its basis, then just adds a bunch of custom objects, methods, properties, that are specific to Inventor to make it easier, you can look most of the basics up online through the 'docs.microsoft.com' website, but it's a really huge site, so you will definitely need to utilize its search function.

Here are a couple of links to get you started, from the vb.net side:

.NET API Reference (very general - tons of 'tip of the iceberg stuff')

System.Collections Namespace  (more specific to Types of collections)

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes