-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathSQLHelperFunctions.bas
More file actions
86 lines (73 loc) · 2.26 KB
/
SQLHelperFunctions.bas
File metadata and controls
86 lines (73 loc) · 2.26 KB
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
Attribute VB_Name = "SQLHelperFunctions"
Public Function toUnix(dt) As Long
toUnix = DateDiff("s", "1/1/1970", dt)
End Function
Public Function toISO(dt) As String
toISO = Format(dt, "YYYY-MM-DD") & "T" & Format(dt, "HH:MM:SS")
End Function
Public Function str(vValue) As String
str = "'" & Replace(vValue, "'", "''") & "'"
End Function
Function JoinArrayofArrays(ByVal vArray As Variant, _
Optional ByVal WordDelim As String = " ", _
Optional ByVal LineDelim As String = vbNewLine) As String
Dim R As Long, Lines() As String
ReDim Lines(0 To UBound(vArray))
For R = 0 To UBound(vArray)
Dim InnerArray() As Variant
InnerArray = vArray(R)
Lines(R) = Join(InnerArray, WordDelim)
Next
JoinArrayofArrays = Join(Lines, LineDelim)
End Function
Function getDimension(Var As Variant) As Long
On Error GoTo Err
Dim i As Long
Dim tmp As Long
i = 0
Do While True
i = i + 1
tmp = UBound(Var, i)
Loop
Err:
getDimension = i - 1
End Function
Public Sub QuickSort(vArray As Variant, inLow As Long, inHi As Long)
Dim pivot As Variant
Dim tmpSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = inLow
tmpHi = inHi
pivot = vArray((inLow + inHi) \ 2)
While (tmpLow <= tmpHi)
While (vArray(tmpLow) < pivot And tmpLow < inHi)
tmpLow = tmpLow + 1
Wend
While (pivot < vArray(tmpHi) And tmpHi > inLow)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
tmpSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = tmpSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (inLow < tmpHi) Then
QuickSort vArray, inLow, tmpHi
End If
If (tmpLow < inHi) Then
QuickSort vArray, tmpLow, inHi
End If
End Sub
Public Function ArrayPush(vArray As Variant, newValue As Variant)
ArrLen = UBound(vArray)
If IsEmpty(vArray(0)) Then
ArrLen = -1
End If
ReDim Preserve vArray(0 To ArrLen + 1)
vArray(ArrLen + 1) = newValue
ArrayPush = vArray
End Function