iLogic help to create multple MultiValue.List from an Excel

iLogic help to create multple MultiValue.List from an Excel

Anonymous
Not applicable
4,941 Views
13 Replies
Message 1 of 14

iLogic help to create multple MultiValue.List from an Excel

Anonymous
Not applicable

please help! i'm stuck 😞

 

here is a simplified example of what i am trying to do...

 

Excel_test.JPG

 

i trying to create multiple MultiValue.List from Excel, and here is a small snippet that i know works...

 

MultiValue.SetList("SIZE", "SIZE-AA", "SIZE-BB", "SIZE-CC")

If SIZE = "SIZE-AA" Then
	GoExcel.TitleRow = 2
	MultiValue.List("MODEL") = GoExcel.CellValues("filename.xls", "Sheet1", "A3", "A5")
ElseIf SIZE = "SIZE-BB" Then
	GoExcel.TitleRow = 7
	MultiValue.List("MODEL") = GoExcel.CellValues("filename.xls", "Sheet1", "A8", "A10")
ElseIf SIZE = "SIZE-CC" Then
	GoExcel.TitleRow = 12
	MultiValue.List("MODEL") = GoExcel.CellValues("filename.xls", "Sheet1", "A13", "A15")
End If

so now, what i would like to do is create another MultiValue.List from the first MultiValue.List.

 

for example, if i select "SIZE-AA" from my "SIZE" multi-list (SIZE-AA, SIZE-BB, SIZE-CC), my next list from "MODEL" would give me "AA100, AA110, AA210", then my next list for eg. "AA110" would be "10, 20, 30,40".

 

can this even be done?

thanks

0 Likes
Accepted solutions (2)
4,942 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable

hello?!?

 

can anyone offer any help here?

0 Likes
Message 3 of 14

Owner2229
Advisor
Advisor

Hi, how about something like this?

 

 

Dim oRow As Integer
Select Case Parameter("MODEL")
    Case "AA100": oRow = 3
    Case "AA110": oRow = 4
    Case "AA120": oRow = 5
    Case "BB100": oRow = 8
    Case "BB110": oRow = 9
    Case "BB120": oRow = 10
    'And so on for C...
End Select

MultiValue.List("SIZE-VALUES") = GoExcel.CellValues("filename.xls", "Sheet1", "B" & oRow, "E" & oRow)

 

BTW. I wouldn't do this task this way at all. I'll load all the values in first place and then work with them (because working with an excel table takes quite some time).

 

Maybe something like this:

 

Sub Main()
MultiValue.SetList("SIZE", "SIZE-AA", "SIZE-BB", "SIZE-CC")
Dim Row As Integer
Dim oMyValues As Variant
GoExcel.Open("filename.xls", "Sheet1")
Row = 1 For j = 3 To 5 ' Set the rows for AA... values
GetValues(oMyValues, Row, j)
Row = Row + 1
Next
For j = 8 To 10 ' Set the rows for BB... values
GetValues(oMyValues, Row, j)
Row = Row + 1
Next
For j = 13 To 15 ' Set the rows for CC... values
GetValues(oMyValues, Row, j)
Row = Row + 1
Next
GoExcel.Close
Dim oModel As String
oModel = Parameter("SIZE")
Dim MyArrayList As ArrayList
For i = 1 To UBound(oMyValues, 1)
If oMyValues(i, 1) = oModel Then
MyArrayList.Add(oMyValues(i, 2))
MyArrayList.Add(oMyValues(i, 3))
MyArrayList.Add(oMyValues(i, 4))
MyArrayList.Add(oMyValues(i, 5))
End If
Next
MultiValue.List("SIZE-VALUES") = MyArrayList
End Sub

Private Sub GetValues(oMyValues As Variant, Row As Integer, j As Integer)
oMyValues(Row, 1) = GoExcel.CellValue("A" & j)
oMyValues(Row, 2) = GoExcel.CellValue("B" & j)
oMyValues(Row, 3) = GoExcel.CellValue("C" & j)
oMyValues(Row, 4) = GoExcel.CellValue("D" & j)
oMyValues(Row, 5) = GoExcel.CellValue("E" & j)
End Usb

 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 4 of 14

Anonymous
Not applicable

thank you so much for replying 🙂

 

but i guess i should have stated that i'm using INV2013 but have plans of upgrading to INV2016 in the very near future

 

i'm trying your code but i'm getting an error with

oMyValues As Variant

Error on Line 4 : 'Variant' is no longer a supported type; use the 'Object' type instead.
Error on Line 34 : 'Variant' is no longer a supported type; use the 'Object' type instead.

 

my knowledge of iLogic is a little more than basic (and i am not a programmer by any means) but i have learned and used lots from this forum

 

my end goal for this snippet of code is to generate a Model number based on the multiple selections given.

 

thanks again for your help

 

-Leonard

0 Likes
Message 5 of 14

Owner2229
Advisor
Advisor

Hi, as I see now I had some errors in the code. This one below should be working. You muss have the folowing parameters in model:

SIZE

SIZE_VALUES

 

 

Sub Main()
    MultiValue.SetList("SIZE", "SIZE-AA", "SIZE-BB", "SIZE-CC")
    Dim Row As Integer
    Dim oMyValues(9, 5) As Object ' Set the range for values (9 rows, 5 columns)
    GoExcel.Open("filename.xls", "Sheet1")
    Row = 1
    For j = 3 To 5 ' Set the rows for AA... values
        GetValues(oMyValues, Row, j)
        Row = Row + 1
    Next
    For j = 8 To 10 ' Set the rows for BB... values
        GetValues(oMyValues, Row, j)
        Row = Row + 1
    Next
    For j = 13 To 15 ' Set the rows for CC... values
        GetValues(oMyValues, Row, j)
        Row = Row + 1
    Next
    GoExcel.Close
    Dim oModel As String
    oModel = Parameter("SIZE")
    Dim MyArrayList As New ArrayList
    For i = 1 To UBound(oMyValues, 1)
	If oMyValues(i, 1) = oModel Then
	    MyArrayList.Add(oMyValues(i, 2))
            MyArrayList.Add(oMyValues(i, 3))
            MyArrayList.Add(oMyValues(i, 4))
            MyArrayList.Add(oMyValues(i, 5))
        End If
    Next
    MultiValue.List("SIZE_VALUES") = MyArrayList
End Sub

Private Sub GetValues(oMyValues As Object, Row As Integer, j As Integer)
    oMyValues(Row, 1) = GoExcel.CellValue("A" & j)
    oMyValues(Row, 2) = GoExcel.CellValue("B" & j)
    oMyValues(Row, 3) = GoExcel.CellValue("C" & j)
    oMyValues(Row, 4) = GoExcel.CellValue("D" & j)
    oMyValues(Row, 5) = GoExcel.CellValue("E" & j)
End Sub 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 6 of 14

Anonymous
Not applicable

zero errors dialog boxes using your code but the parameter "SIZE_VALUES" doesn't show a multi-value list in the parameter list

 

also, what about the "Model" parameter that you had shown? should that be included in what you have shown?

 

 

 

 

 

 

0 Likes
Message 7 of 14

Owner2229
Advisor
Advisor

Hi, you have to run it once, then go to parameters (or do it using another rule) and select an value for the "SIZE" parameter. Then run this rule again.

I have added parameter check so you don't need to care if the parameter is created or not. The parameter "MODEL" is not needed as all the values are now stored in the "oMyValues" object.

 

 

Sub Main()
    CheckParam("SIZE")
MultiValue.SetList("SIZE", "SIZE-AA", "SIZE-BB", "SIZE-CC") Dim Row As Integer Dim oMyValues(9, 5) As Object ' Set the range for values (9 rows, 5 columns) GoExcel.Open("filename.xls", "Sheet1") Row = 1 For j = 3 To 5 ' Set the rows for AA... values GetValues(oMyValues, Row, j) Row = Row + 1 Next For j = 8 To 10 ' Set the rows for BB... values GetValues(oMyValues, Row, j) Row = Row + 1 Next For j = 13 To 15 ' Set the rows for CC... values GetValues(oMyValues, Row, j) Row = Row + 1 Next GoExcel.Close Dim oModel As String oModel = Parameter("SIZE") Dim MyArrayList As New ArrayList For i = 1 To UBound(oMyValues, 1) If oMyValues(i, 1) = oModel Then MyArrayList.Add(oMyValues(i, 2)) MyArrayList.Add(oMyValues(i, 3)) MyArrayList.Add(oMyValues(i, 4)) MyArrayList.Add(oMyValues(i, 5)) End If Next
CheckParam("SIZE_VALUES") MultiValue.List("SIZE_VALUES") = MyArrayList End Sub Private Sub GetValues(oMyValues As Object, Row As Integer, j As Integer) oMyValues(Row, 1) = GoExcel.CellValue("A" & j) oMyValues(Row, 2) = GoExcel.CellValue("B" & j) oMyValues(Row, 3) = GoExcel.CellValue("C" & j) oMyValues(Row, 4) = GoExcel.CellValue("D" & j) oMyValues(Row, 5) = GoExcel.CellValue("E" & j) End Sub Private Sub CheckParam(oParaName As String) oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters Try Parameter(oParaName) = Parameter(oParaName) Catch oParameter = oParameters.AddByValue(oParaName, "", UnitsTypeEnum.kTextUnits) End Try End Sub

 

 

Here below is the rule to pick one of the "SIZE" parameter values. Use the number to pick (first/second/...) value from the parameter list.

 

Try
    Parameter("SIZE") = Parameter("SIZE")
Parameter("SIZE") = MultiValue.List("SIZE").Item(1)
Catch MsgBox("The parameter 'SIZE' doesn't exist") End Try

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 8 of 14

Anonymous
Not applicable

hey, i'm sorry for not replying soon, i got busy at work and couldn't look at this code

 

i also want to say thank you so much for your help here, i really do appreciate all your efforts

 

but i'm still running into issues here with some of this code. i've tried this in INV2013 and INV2016 and i'm getting the same errors

 

the 1st error is in the "MODEL" snippet: Excel cell not found (bad cell address?): "B0"

 

and the 2nd error is in the main code snippet. the parameter "SIZE_VALUES" doesn't return the Multi-value list. the list is empty

 

and i do have one more small favor. for the benefit of myself and others here trying to learn iLogic, could you add more comments to the code so that i/we could understand what exactly is going on here

 

once again, thanks again for your help here 🙂

 

0 Likes
Message 9 of 14

Owner2229
Advisor
Advisor
Accepted solution

Hi, the "MODEL" snipset is supposed to be placed after your original code, like this:

 

 

' Set the list of "SIZE" parameter
MultiValue.SetList("SIZE", "SIZE-AA", "SIZE-BB", "SIZE-CC")
' Determine the SIZE value If SIZE = "SIZE-AA" Then ' Load values from excel
GoExcel.TitleRow = 2
' Fill the "MODEL" parameter with found values MultiValue.List("MODEL") = GoExcel.CellValues("filename.xls", "Sheet1", "A3", "A5") ElseIf SIZE = "SIZE-BB" Then GoExcel.TitleRow = 7 MultiValue.List("MODEL") = GoExcel.CellValues("filename.xls", "Sheet1", "A8", "A10") ElseIf SIZE = "SIZE-CC" Then GoExcel.TitleRow = 12 MultiValue.List("MODEL") = GoExcel.CellValues("filename.xls", "Sheet1", "A13", "A15") End If Dim oRow As Integer
' Pick the value from "MODEL" parameter Select Case Parameter("MODEL") ' Set searched row, according to "MODEL" parameter value
Case "AA100": oRow = 3 Case "AA110": oRow = 4 Case "AA120": oRow = 5 Case "BB100": oRow = 8 Case "BB110": oRow = 9 Case "BB120": oRow = 10 'And so on for C... End Select
' Fill the "SIZE-VALUES" parameter with vaues from the excel table,
' using the previously set "oRow" variable with combination of columns "B" and "E" MultiValue.List("SIZE-VALUES") = GoExcel.CellValues("filename.xls", "Sheet1", "B" & oRow, "E" & oRow)

 

Here to the second snipset:

 

 

Sub Main()
    ' Check if the parameter "SIZE" does exist and has valid value. End this makro if not.
If CheckParam("SIZE") = "" Then MultiValue.SetList("SIZE", "SIZE-AA", "SIZE-BB", "SIZE-CC")
MsgBox("Please select value for SIZE parameter first.")
Exit Sub
End If
Dim Row As Integer
' Create new object table to store the excel table in Dim oMyValues(9, 5) As Object ' Set the range for values (9 rows, 5 columns)
' Open excel document GoExcel.Open("filename.xls", "Sheet1") Row = 1
' Load all values from the excel table For j = 3 To 5 ' Set the rows for AA... values GetValues(oMyValues, Row, j) Row = Row + 1 Next For j = 8 To 10 ' Set the rows for BB... values GetValues(oMyValues, Row, j) Row = Row + 1 Next For j = 13 To 15 ' Set the rows for CC... values GetValues(oMyValues, Row, j) Row = Row + 1 Next
' Close excel table GoExcel.Close Dim oModel As String oModel = Parameter("SIZE")
' Create new array list, taht will be used to fill the "SIZE_VALUES" parameter Dim MyArrayList As New ArrayList
' Go throught each of rows in previously created object table
' and check if any of the rows match our needs For i = 1 To UBound(oMyValues, 1) If oMyValues(i, 1) = oModel Then MyArrayList.Add(oMyValues(i, 2)) MyArrayList.Add(oMyValues(i, 3)) MyArrayList.Add(oMyValues(i, 4)) MyArrayList.Add(oMyValues(i, 5)) End If Next
' Check if the parameter "SIZE_VALUES" does exist NewParameter = CheckParam("SIZE_VALUES")
' Set the values for "SIZE_VALUES" parameter MultiValue.List("SIZE_VALUES") = MyArrayList End Sub
' Sub-function used to load values from the excel table Private Sub GetValues(oMyValues As Object, Row As Integer, j As Integer) oMyValues(Row, 1) = GoExcel.CellValue("A" & j) oMyValues(Row, 2) = GoExcel.CellValue("B" & j) oMyValues(Row, 3) = GoExcel.CellValue("C" & j) oMyValues(Row, 4) = GoExcel.CellValue("D" & j) oMyValues(Row, 5) = GoExcel.CellValue("E" & j) End Sub
' Function used to check if the parameter exists and create it if not Private Function CheckParam(oParaName As String) As String ' Return value as string oParameters = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters Try
Parameter(oParaName) = Parameter(oParaName)
CheckParam = Parameter(oParaName) Catch oParameter = oParameters.AddByValue(oParaName, "", UnitsTypeEnum.kTextUnits)
CheckParam = "" End Try End Sub

 

Here below is the rule to pick one of the "SIZE" parameter values. Use the number to pick (first/second/...) value from the parameter list.

 

Try
    Parameter("SIZE") = Parameter("SIZE")
Parameter("SIZE") = MultiValue.List("SIZE").Item(1)
Catch MsgBox("The parameter 'SIZE' doesn't exist") End Try

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 10 of 14

Anonymous
Not applicable

wow, i'm such a newbie [[face palm]] i couldn't understand what i was missing in the first snippet code

i've been staring at this code for days

 

thank you for all your help

 

[edit]

**i'm getting an error when i run this: Error on Line 68 : 'End Function' expected.

 and my "SIZE_VALUES" is now a Multi-Value but not a complete list

 

did you do a part file to create this code and if you did could you attach it here and i'll compare it to my copy?

 

thanks again 🙂

 

p.s.

do you think this is the best way to approach this task? or do you think there is a better way?

0 Likes
Message 11 of 14

Owner2229
Advisor
Advisor

Hi, the error is obvious as on the last row I have "End Sub" instead of "End Function".

 

The two code snipsets I send you in the last post are separate solutions, but you got it, right? 😉

 

No I didn't create any test files for this rule, so I wasn't able ot test it. I just made it blindly 😄

I was ussing the picture you posted in the first post as a data source, so if you have more date in the excel file, than you'll need to adjust the code.

 

In the first solution (FS) is missing the "SIZE-DD" from your picture. But it's included in the second solution.

In FS it can be added at place where is this:

'And so on for C...  

 

It's 6th row from bottom.

If you want me to adjust the code for you then send me the excel file or tell me how many more rows and/or columns you have in it.

And if the empty/description rows are the same (two).

It can also be done programaticaly if it will vary over time.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 12 of 14

Anonymous
Not applicable

hey! thanks again for replying. i'm sorry for not getting back sooner

 

once again, thank you so much for your help. i really do appreciate all your efforts here.

 

i did spend quite a few hours this past weekend going thru your code, and modifying the errors in the code and completing the code where you indicated.

 

i will say that i'm very, very impressed that you wrote the code "blindly" and without creating a test model. like most ppl here, i'm teaching myself iLogic and without ppl like you and this forum, i'd still be quite lost.

 

and to be honest, i don't fully understand (from my inexperience in iLogic) a good portion of your code, so i have to read each line of code a few times to get a small glimps of some understanding of it 😉

 

for example, the last bit of code (rule to pick one of the "SIZE" parameter values), i'm unsure what/how/where to do with this code.

 

but, for the most part, i did manage to get your code working. tho what took you minutes took me a few hours LOL

 

thanks again

0 Likes
Message 13 of 14

Owner2229
Advisor
Advisor
Accepted solution

Hi, you mean this one below? I send it to you as a tool so you can use it as a separate rule to test your code.

It just checks if the parameter "SIZE" exists and if so then it will pick the first value (so you dont need to go to parameters and look for it).

The zero in the ".Item(0)" means it will pick the first item, because it starts numbering from zero instead of one.

So if we will change it to "MultiValue.List("SIZE").Item(1)", it will pick the second item from the list.

 

Try
    ' Atempt to read the parameter "SIZE"
Parameter("SIZE") = Parameter("SIZE")
' If it doesn't throw an error then it will pass here,
' so we can pick the first item from the list in "SIZE" parameter Parameter("SIZE") = MultiValue.List("SIZE").Item(0) Catch ' If the reading of the parameter fails, the "Try" command will send us here
' As the reading of the parameter failed we can assume it doesn't exist
MsgBox("The parameter 'SIZE' doesn't exist") End Try
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
Message 14 of 14

Anonymous
Not applicable

once again, thanks so much. i appreciate all your help here 🙂

 

trying to learn iLogic without this forum and helpful people like you would make this task more difficult. i have been using Inventor since R1 and only since 2013 have i attempted to learn iLogic (with very slow progress, i must say LOL)

 

with your experience, is there any other more efficient way to approach this task? for example, instead of 2 separate rules, having one instead?

 

best regards,

-Leonard

0 Likes