Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can this code be simpler

4 REPLIES 4
Reply
Message 1 of 5
Dennisvercauteren
308 Views, 4 Replies

Can this code be simpler

Hi, 

I am pretty new to Ilogic, an experimenting a bit. 

Can this code be simpler ? 

 

If GoExcel.CellValue(ExcelFile, "Sheet1", "A1")=1 Then 
    Component.IsActive("A1") = True
Else
    Component.IsActive("A1") = False 
End If

If GoExcel.CellValue(ExcelFile, "Sheet1", "B1")=1 Then 
    Component.IsActive("B1") = True
Else
    Component.IsActive("B1") = False 
End If

If GoExcel.CellValue(ExcelFile, "Sheet1", "C1")=1 Then 
    Component.IsActive("C1") = True
Else
    Component.IsActive("C1") = False 
End If
4 REPLIES 4
Message 2 of 5

In general, (almost) everytime you have a if/else if can be replaced (on the syntax level).

 

So this:

If GoExcel.CellValue(ExcelFile, "Sheet1", "A1")=1 Then
    Component.IsActive("A1") = True
Else
    Component.IsActive("A1") = False
End If

 

Can be this:
Dim b as Boolean = (GoExcel.CellValue(ExcelFile, "Sheet1", "A1")=1)
Component.IsActive("A1") = b = Not b

 

But it's up to you...

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 3 of 5
AlexSu
in reply to: Dennisvercauteren

I used to do this (in VBA)...

 

Dim int_charCode As Integer
    For int_charCode = 65 To 67  'Loop 'A' to 'C'
        Component.IsActive(Chr(int_charCode) & "1") = IIf(ws_test.Range(Chr(int_charCode) & "1").Value = 1, True, False)
    Next

  iLogic....

Dim int_charCode As Integer = 65
For int_charCode = 65 To 67
	Component.IsActive(ChrW(int_charCode) & "1") = If( GoExcel.CellValue("D:\TestiLogic.xlsx", "Sheet1", ChrW(int_charCode) & "1") = 1, True, False)
Next

 

Regards,
Alex Su
Autodesk Autocad & Inventor 2012 Certified Pro
Autodesk Inventor 2012 Certified Instructor (ACI)
Autodesk Inventor 2012 Certification Evaluator (ACE)
Message 4 of 5

Augusto, can you explain the extra "= Not b" on your last line? I don't understand. 

 

Edit: Unless you were simply showing how one could also use Not b to set visiblity to the opposite of the test case

Inventor 2013 SP 1.1

If you wish to make an apple pie from scratch, you must first invent the universe.
Message 5 of 5

Sorry that 'Not b' is not required... some copy/paste mistake... 🙂

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report