Usings Strings to Reduce Code Line Count

Usings Strings to Reduce Code Line Count

kevin
Explorer Explorer
224 Views
1 Reply
Message 1 of 2

Usings Strings to Reduce Code Line Count

kevin
Explorer
Explorer

Hi
I am trying to learn to use Inventor (iLogic). I've had reasonable success to date in generally Googling my questions.
One of my colleagues has seen the  code I've written and tried to help me to reduce the quantity of repetitive similar statements my using strings (which is new to me). 
What I had been writing is shown below but single rules have exceeded 5k lines (very small example below;

If AS_DIA = 900 Then Component.IsActive("STD-PT-038-014-POS-M:1")= False
If AS_DIA = 900 Then Component.IsActive("STD-PT-038-014-POS-N:1")= False
If AS_DIA = 900 Then Component.IsActive("STD-PT-038-014-POS-O:1")= False
If AS_DIA = 900 Then Component.IsActive("STD-PT-038-014-POS-P:1")= False

If AS_DIA = 1200 Then Component.IsActive("STD-PT-038-014-POS-M:1")= False
If AS_DIA = 1200 Then Component.IsActive("STD-PT-038-014-POS-N:1")= False
If AS_DIA = 1200 Then Component.IsActive("STD-PT-038-014-POS-O:1")= False
If AS_DIA = 1200 Then Component.IsActive("STD-PT-038-014-POS-P:1") = False

 He gave me an example to get me started but I am unable to get it to work. I keep getting the error "Property access must assign to the property or use its value." I have researched this but can't find a helpful example to guide me. Below is the code I am having trouble with;

Sub Main Component.IsActive(SetAsFalse As String [])

For Each oString As String In SetAsTrue
	Component.IsActive(oString) = True
Next

For  Each oString As String In SetAsFalse
	Component.IsActive(oString) = False
Next
If AS_DIA = 750 Then Component.IsActive (SetAsTrue = {""},SetAsFalse = {"STD-PT-038-014-POS-M:1","STD-PT-038-014-POS-N:1","STD-PT-038-014-POS-O:1","STD-PT-038-014-POS-P:1"})

End Sub

 Any help/ guidance would be really appreciated
Best Regards

0 Likes
225 Views
1 Reply
Reply (1)
Message 2 of 2

A.Acheson
Mentor
Mentor

Hi @kevin 

Old request but if you use Option Explicit On (Optional Use) you will find many errors.  The ilogic editor allows for less declarations of object variables but this can lead to issues trouble shooting later. The first error relates to "SetAsTrue" you had not defined what this object was to be in your case a string array or list of string.

AAcheson_0-1687625424965.png

Some examples of using strings in either a string array or list of string

'Option Explicit On
Sub Main 
	' Method 1, string array
	Dim setasTrue1() As String = {"STD-PT-038-014-POS-M:1","STD-PT-038-014-POS-N:1","STD-PT-038-014-POS-O:1","STD-PT-038-014-POS-P:1"}
	Dim d1 As String = InputListBox("Prompt", setasTrue1, d1, Title := "Title", ListName := "List")

	For Each string1 As String In setasTrue1
		MessageBox.Show(string1, "Title")
	Next
	
	' Method 2, List of String
	Dim setasTrue2 As New List(Of String)  
	setasTrue2.Add("STD-PT-038-014-POS-M:1")
	setasTrue2.Add("STD-PT-038-014-POS-N:1")
	setasTrue2.Add("STD-PT-038-014-POS-O:1")
	setasTrue2.Add("STD-PT-038-014-POS-P:1")
	Dim d2 As String = InputListBox("Prompt", setasTrue1, d2, Title := "Title", ListName := "List")

	For Each string2 As String In setasTrue2
		MessageBox.Show(string2, "Title")
	Next

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes