Can this code be simpler

Can this code be simpler

Anonymous
Not applicable
428 Views
4 Replies
Message 1 of 5

Can this code be simpler

Anonymous
Not applicable

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
0 Likes
429 Views
4 Replies
Replies (4)
Message 2 of 5

augusto.goncalves
Alumni
Alumni

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
0 Likes
Message 3 of 5

Anonymous
Not applicable

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

 

0 Likes
Message 4 of 5

Anonymous
Not applicable

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

0 Likes
Message 5 of 5

augusto.goncalves
Alumni
Alumni

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

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes