-
Notifications
You must be signed in to change notification settings - Fork 335
/
ArrayList.rvb
112 lines (105 loc) · 3.54 KB
/
ArrayList.rvb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' ArrayList.rvb -- September 2009
' If this code works, it was written by Dale Fugier.
' If not, I don't know who wrote it.
' Works with Rhino 4.0.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Appends another array to the end of the array.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArrayAppend(ByRef arr, ByVal arr0)
Dim i, list
If IsArray(arr) Then
Set list = CreateObject("System.Collections.ArrayList")
For i = 0 To UBound(arr)
Call list.Add(arr(i))
Next
For i = 0 To UBound(arr0)
Call list.Add(arr0(i))
Next
arr = list.ToArray()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Inserts a new element at a given position in the array.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArrayInsert(ByRef arr, ByVal pos, ByVal val)
Dim i, list
If IsArray(arr) Then
Set list = CreateObject("System.Collections.ArrayList")
For i = 0 To UBound(arr)
Call list.Add(arr(i))
Next
Call list.Insert(pos, val)
arr = list.ToArray()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Inserts a new element at a given position in the array.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArrayRemoveAt(ByRef arr, ByVal pos)
Dim i, list
If IsArray(arr) Then
Set list = CreateObject("System.Collections.ArrayList")
For i = 0 To UBound(arr)
Call list.Add(arr(i))
Next
Call list.RemoveAt(pos)
arr = list.ToArray()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Removes duplicate items from the array.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArrayCull(ByRef arr)
Dim i, list, tmp
If IsArray(arr) Then
Set list = CreateObject("System.Collections.ArrayList")
For i = 0 To UBound(arr)
If Not list.Contains(arr(i)) Then
Call list.Add(arr(i))
End If
Next
arr = list.ToArray()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Sorts the elements in the array.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArraySort(ByRef arr)
Dim i, list
If IsArray(arr) Then
Set list = CreateObject("System.Collections.ArrayList")
For i = 0 To UBound(arr)
Call list.Add(arr(i))
Next
Call list.Sort()
arr = list.ToArray()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Reverse the order of the elements in the array.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArrayReverse(ByRef arr)
Dim i, list
If IsArray(arr) Then
Set list = CreateObject("System.Collections.ArrayList")
For i = 0 To UBound(arr)
Call list.Add(arr(i))
Next
Call list.Reverse()
arr = list.ToArray()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Dumps the array to the Rhino command window.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ArrayDump(ByVal arr)
Dim i
If IsArray(arr) Then
For i = 0 To UBound(arr)
Call Rhino.Print("Item(" & CStr(i) & ") = " & CStr(arr(i)))
Next
End If
End Sub