Hi all,
I have a somewhat unexpected problem. I am making parts with iLogic-rules, and now I have one part that just won´t let me write statements such as "Else" or "End If", I just get an error message saying "'ElseIf' must be preceded by a matching 'If' or 'ElseIf'."
The program looks like this:
If Hole = 1 Then Feature.IsActive("Hole") = True
If Hole = 0 Then Feature.IsActive("Hole") = False
And it works great as long as I don't try to finish it with "End If". But why??? All other iLogic rules I have written have required an "End If"-statement after using an If-statement.
The only difference between this iLogic-rule an all other rules I wrote is that this one is linked to a spreadsheet created in Excel 2003. Does linking to Excel make If-statements work different in iLogic?
Version: Inventor Professional 2011
Please see attached files
Best regards,
Mattias
Solved! Go to Solution.
Solved by jeff.pek. Go to Solution.
End If has to be on a separate line by itself. The following code should work:
If Hole = 1 Then Feature.IsActive("Hole") = True End If If Hole = 0 Then Feature.IsActive("Hole") = False End If
Is the rule giving you a compile error, or any kind of error? Or are you just finding that it doesn't work?
If it's not working, the problem might have something to do with the Excel link. iLogic does not see the Excel changes if you edit the spreadsheet without the part open in Inventor. When you later open the part, the parameters change, but iLogic is not aware of it. You can work around this problem by using the Event Triggers command under Manage -> iLogic. Double-click on the After Open Document event and select your rule to run on that event.
Dear Mike,
I am aware that the "End If" expression needs to be on a separate program line. In the last few weeks I have successfully created at least 50 parts with different iLogic rules, so I'm starting to get the hang of it.
But this specific file behaves different. I do get a compile error if I try to add an "End If"-statement. Normally I would get a compile error if I forgot the "End If". I do not understand why this file is behaving so different.
Again, please see the files attached to the original message (part file + excel document) . Please take the time to open the part and try yourself to add "End If" to the rule. See what happens.
Best regards,
Mattias
Hi Mattias -
The IF statement syntax is different, depending on if you keep everything on one line, or split it up.
Here's a relevant article:
http://www.java2s.com/Tutorial/VB/0080__Statements/SinglelinevsMultilineIfstatement.htm
I hope this is helpful.
Jeff
Hello Jeff,
That article was great, now I understand why it didn't work as expected. And I feel a bit like a noob... 🙂
Now I will go read a book about VBA programming...
Regards
/ Mattias