create variable and assign sequential values ​​using ilogic inventor

create variable and assign sequential values ​​using ilogic inventor

luis_sanderKNSGP
Explorer Explorer
725 Views
4 Replies
Message 1 of 5

create variable and assign sequential values ​​using ilogic inventor

luis_sanderKNSGP
Explorer
Explorer

Hello!

 

I'm trying to do this operation below using ilogic inventor, but it doesn't work. Basically create the variables F1, F2, F3 and F4 and then assign the values ​​1, 2, 3 and 4 or 0. Any help is welcome. 

 

i = 0
While i<4
	i = i + 1
	oxyfuel= "oxyfuel_F" & i
	If Feature.IsActive(oxyfuel) Then
		"F" & i = i
	Else
		"F" & i = 0
	End If
End While

MessageBox.Show("CF" & F1 & F2 & F3 & F4, "Part name")

 

0 Likes
Accepted solutions (1)
726 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

Hi @luis_sanderKNSGP.  I am not sure what all you were trying to achieve there, but below is my interpretation of what you wanted to achieve.  You can not 'declare' or 'define' a variable by concatenating its name together like a String.  The result of that is just a String, not a variable for representing a value.  So, I 'declared' those F# variables before the loop, then set their values within the loop, so that the message outside the loop will recognize them.

Dim i As Integer = 0
Dim F1, F2, F3, F4 As Integer
While i <= 4
	i += 1
	Dim oxyfuel As String = "oxyfuel_F" & i
	If Feature.IsActive(oxyfuel) Then
		If i = 1 Then
			F1 = i
		ElseIf i = 2 Then
			F2 = i
		ElseIf 1 = 3 Then
			F3 = i
		ElseIf i = 4 Then
			F4 = i
		End If
	Else
		If i = 1 Then
			F1 = 0
		ElseIf i = 2 Then
			F2 = 0
		ElseIf 1 = 3 Then
			F3 = 0
		ElseIf i = 4 Then
			F4 = 0
		End If
	End If
End While

MessageBox.Show("CF" & F1 & F2 & F3 & F4, "Part name")

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

luis_sanderKNSGP
Explorer
Explorer

Hi  WCrihfield, thank you so much. 

 

This code performs what I need. However, the idea was to "create" the F1, F2... Fn. For example, if it were necessary to use "n" numbers of "F." Depending on the condition, this "F" should store the value of i or 0.

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

OK.  Well, since we can't do that with actual variables, we could likely achieve similar functionality with some sort of collection type object, such as an Array of Integer, or List(Of Integer), or similar.  Both of those vb.net based collection types start at zero though, not one, like most types of collections based in vb.net.  On the flip side, most collection types that are defined within the Inventor API or iLogic API start at one, instead of zero, to make them more 'natural' feeling to work with.

 

Below is another example you can play around with.  It is using a simple Array of Integers, with zero as the starting value.  That way, we do not even need the 'Else' side of the If statement.  Then, within the loop, and within the If statement, it specified the element within the Array by the current value of 'i' minus one, since the array starts at zero, and changes the value of that element to the current value of 'i'.  After the iteration, we can either just use that Array variable directly within your message, or we can extract the individual Array values to static variables first, then use those variables within the message.  Just another thought to reduce required code while maintaining similar functionality.

Dim i As Integer = 0
Dim oResults() As Integer = {0,0,0,0}
While i <= 4
	i += 1
	Dim oxyfuel As String = "oxyfuel_F" & i
	If Feature.IsActive(oxyfuel) Then
		'i-1, because Array's start at zero, not one
		oResults(i - 1) = i
	End If
End While
MessageBox.Show("CF" & oResults(0) & oResults(1) & oResults(2) & oResults(3), "Part name")

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

luis_sanderKNSGP
Explorer
Explorer
Exactly what I was thinking. thank you very much!
0 Likes