-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.bas
180 lines (112 loc) · 3.99 KB
/
library.bas
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
''''''''''''''''''''''''''''''''''''''''
' Function Library
''''''''''''''''''''''''''''''''''''''''
' DATA READING FUNCTIONS
Function returnLine(row, activeColumnCount) As Variant
Dim arr As Variant ' <-- Array of column headers
ReDim arr(0 To activeColumnCount)
For i = 0 To activeColumnCount
c = i + 1
arr(i) = Cells(row, c).value
Next i
returnLine = arr
End Function
Function buildDictionary(startingRow, lastRow, headers) As Variant
Dim sheetData As Variant
ReDim sheetData(1 To 1)
Index = 1
For R = startingRow To lastRow
ReDim Preserve sheetData(1 To Index)
Set sheetData(Index) = CreateObject("Scripting.Dictionary")
For c = 1 To UBound(headers) ' <-- Assigns key:value pair for every line item on row.
lineItem = Cells(R, c).value
sheetData(Index).Add headers(c), lineItem
Next c
Index = Index + 1
Next R ' <-- Moves on to next row.
buildDictionary = sheetData
End Function
Function continueDictionary(Dictionary, startingRow, lastRow, headers)
Index = (UBound(Dictionary) + 1)
For R = startingRow To lastRow
ReDim Preserve Dictionary(1 To Index)
Set Dictionary(Index) = CreateObject("Scripting.Dictionary")
For c = 1 To UBound(headers) ' <-- Assigns key:value pair for every line item on row.
lineItem = Cells(R, c).value
Dictionary(Index).Add headers(c), lineItem
Next c
Index = Index + 1
Next R ' <-- Moves on to next row.
continueDictionary = Dictionary
End Function
Function dataPrint(haystack, start, last)
Debug.Print ("dataPrint")
For Index = start To last
On Error Resume Next
For Each key In haystack(Index).keys()
Debug.Print ("Row: " & Index & "," & "Column:" & key & "," & haystack(Index)(key))
Next
Next Index
End Function
Function arrayPrint(haystack, start, last)
For Index = start To last
Debug.Print (haystack(Index))
Next Index
End Function
Function isDuplicate(needle, haystackArr)
isDuplicate = False
For Index = LBound(haystackArr) To UBound(haystackArr)
If (needle = haystackArr(Index)) Then
isDuplicate = True
Exit For
End If
Next Index
End Function
' ADVANCED READING FUNCTIONS
Function combineArray(domArray, subArray)
combinedLength = UBound(domArray) + UBound(subArray)
ReDim Preserve domArray(1 To combinedLength)
For Index = 1 To UBound(subArray)
domArray(UBound(domArray) + Index) = subArray(Index)
Next Index
combineArray = domArray
End Function
Function inputPair(start, last, key, value, haystack) ' <-- Inputs individual key:value pair into dictionary.
For Index = start To last
haystack(Index).Add key, value
Next Index
End Function
' DATA MANIPULATION FUNCTIONS
Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
Dim i
For i = LBound(arr) To UBound(arr)
If arr(i) = stringToBeFound Then
IsInArray = True
Exit Function
End If
Next i
IsInArray = False
End Function
Function cleaveName(x As String) As Variant
x = replace(x, "-", "(")
x = replace(x, " ", "(")
cleaveName = Split(x, "(")
End Function
' REFERENCING FUNCTIONS
Function readFiles(path)
Dim fileArray As Variant
ReDim fileArray(0 To 0)
Dim oFSO As Object
Dim directory As Object
Dim Files As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set directory = oFSO.GetFolder(path)
Set dirFiles = directory.Files
ReDim fileArray(1 To dirFiles.Count)
Index = 1
For Each File In dirFiles
fileArray(Index) = File.Name
Index = Index + 1
Next File
readFiles = fileArray
End Function