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: 

Non-Defined (Dynamic) Arrays in iLogic

1 REPLY 1
SOLVED
Reply
Message 1 of 2
MegaJerk
2128 Views, 1 Reply

Non-Defined (Dynamic) Arrays in iLogic

Is there a way to declare a non-bound array (dynamic array?) in iLogic?

There are examples of set bounds array:

 

MyDoubleValues = New Double(){1.2,2.2,3.3}

 

But doing something like:

 

Dim MyDoubleValues() As Double  ---Or---  MyDoubleValues = New Double()

 

Results in an error. On the other hand, the following totally works:

 

Dim MyDoubleValues(1) As Double

 

Which creates an array with a Ubound of 2



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
1 REPLY 1
Message 2 of 2
MegaJerk
in reply to: MegaJerk

Alright, I sort of solved my own problem. The code below is a test showing that you can make a single slot defined array, make it grow based on user inputs, sort it, and make it shrink to remove any duplicate entries. It's not pretty, but I never claimed that I was a coding genius 😉 

What it does: Produces an input box asking for numerical inputs. When you are done hit cancel or simply hit enter (leaving the input blank), and you will be asked to confirm. Once you confirm, the array will be sorted from lowest to highest and returned to you via a message box. 

The intention of this test was to figure out a way to capture a series of user inputs in a dynamic (on the fly sort of) way, to allow for the later combination of the user array and any predefined array (or series of numbers) that existed in my Inventor assembly as calculated parameters. 

 

 

////////////////////////////////////

 

Oh one last note : This is sorting using the Bubble Sort method.

 

///////////////////////////////////

 

Dim holder As Object
Dim fakeArray(0) As String
Dim i As Integer
Dim holderList As String

i = 0

holder = InputBox("Please Enter Your Channel Possitions", "Number Muncher", "")

If IsNumeric(holder) = True Then
fakeArray(i) = holder

While holder <> ""

holderList = Join(fakeArray,",")
holder = InputBox("Please Enter Your Next Value" & vbCrLf &" The Current Values are : " & holderList, "Number Muncher", "") '

If IsNumeric(holder) = True Then
i = i+1
ReDim Preserve fakeArray(i)
fakeArray(i) = holder
Else

ButtonValueTest=MsgBox("Would You Like To Stop Entering Values?", vbYesNo,"Question Time!")
If ButtonValueTest = vbYes Then
'MessageBox.Show("You pressed : Yes","Results")
Exit While
Else
'MessageBox.Show("You pressed : No","Results")
holder = "1"
End If

End If
End While
End If

'MessageBox.Show(UBound(fakeArray),"")


Dim ArraySize As Integer
ArraySize = UBound(fakeArray)

Dim slot1, slot2, swapped As Double
Dim APos As Integer
Dim IdentCount As Integer

swapped = 2

If ArraySize < 1Then
MessageBox.Show("Array has been sorted: " & holderList, "")
Else If ArraySize > 0 And ArraySize < 2 Then
slot1 = fakeArray(0)
slot2 = fakeArray(1)
If slot1 < slot2 Then
holderList = Join(fakeArray,",")
MessageBox.Show("Array has been sorted: " & holderList,"")
Else If slot1 > slot2 Then
fakeArray(0) = slot2
fakeArray(1) = slot1
holderList = Join(fakeArray,",")
MessageBox.Show("Array has been sorted: " & holderList,"")
Else If slot1 = slot2 Then
'Remove(fakeArray(1))
ReDim Preserve fakeArray(0)
holderList = Join(fakeArray,",")
MessageBox.Show("An Array has been changed to: " & holderList,"")
End If
Else If ArraySize > 1 Then
'MessageBox.Show("Array Larger Than 1", "")
While swapped > 1
swapped = 1

For APos = 1 To UBound(fakeArray) Step 1
'MessageBox.Show("Looping through Array","")

slot1 = fakeArray(Apos-1)
slot2 = fakeArray(Apos)

If slot2 < slot1 Then
fakeArray(Apos-1) = slot2
fakeArray(Apos) = slot1
swapped = 2
Else If slot2 = slot1 Then

For IdentCount = APos To UBound(fakeArray) Step 1
'MessageBox.Show("Upper Bound: " & UBound(fakeArray) & " And Ident " & IdentCount, "")
If IdentCount = UBound(fakeArray) Then
ReDim Preserve fakeArray(IdentCount - 1)
Apos = 1
'MessageBox.Show("New UBound: " & UBound(fakeArray),"")





Exit For
End If
fakeArray(IdentCount) = fakeArray(IdentCount + 1)

Next
swapped = 2
End If
'MessageBox.Show("APos : " & APos,"")
If APos >= UBound(fakeArray)
Exit For
End If

Next

If swapped <> 2 Then
swapped = 0
End If
End While
holderList = Join(fakeArray,",")
MessageBox.Show("Array has been sorted down to: " & holderList,"")
End If

 


 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub

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

Post to forums  

Autodesk Design & Make Report