Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Access 2007, not recoginizing Array.Sort Posted by jritchie on 24 Jul 2011 at 4:47 PM
I have an Access 2007 database project and have included the references to System and mscorlib.dll which according to MS documentation should include the Array methods.

Access still does not recognize Array.Sort in my code.
Dim aA(5) as integer
aA(0) = 2
aA(1) = 4
aA(2) = 0
aA(3) = 1
aA(4) = 3

Array.Sort(aA)

Will not compile, what am I missing here? Yeah, I can write a quicksort or bubblesort but why when it should have the System.Collections already referenced when I added System and mscorlib.dll to the project.
Help, please.
Report
Re: Access 2007, not recoginizing Array.Sort Posted by dokken2 on 4 Aug 2011 at 11:05 AM
mscorlib.dll is a .Net framework assembly, remember that Office and Access are based on COM (and have no idea of what .net is).

I use a class module-


'--- CLASS MODULE TO SORT ANY ARRAY ---
Dim V1() As String, LB As Long, UB As Long, i As Integer

'return pointer to array, i.e. Variant = Object.GetArray
Public Property Get GetArray() As Variant
GetArray = V1()
End Property

'get the array, i.e. Object.GetArray = Array()
Public Property Let GetArray(V As Variant)
LB = LBound(V): UB = UBound(V) 'lower/upper bounds
ReDim V1(LB To UB) As String
For i = LB To UB: V1(i) = CStr(V(i)): Next 'convert to string array
End Property

'method to sort the array, i.e. Object.Sort
Public Sub Sort()
LB = LBound(V1): UB = UBound(V1)
QuickSort V1(), LB, UB
End Sub


'Call QuickSort(MyArray, LBound(MyArray), UBound(MyArray))
Private Sub QuickSort(ByRef arArray() As String, ByVal LB As Long, ByVal UB As Long)
Dim P1 As Long, P2 As Long, Ref As String, TEMP As String
P1 = LB
P2 = UB
Ref = arArray((P1 + P2) / 2)

Do
Do While (arArray(P1) < Ref): P1 = P1 + 1: Loop
Do While (arArray(P2) > Ref): P2 = P2 - 1: Loop

If P1 <= P2 Then
TEMP = arArray(P1)
arArray(P1) = arArray(P2)
arArray(P2) = TEMP
P1 = P1 + 1
P2 = P2 - 1
End If
Loop Until (P1 > P2)

If LB < P2 Then Call QuickSort(arArray, LB, P2)
If P1 < UB Then Call QuickSort(arArray, P1, UB)
End Sub
'--- end class module ---




Sub Sample()
'INIT ARRAYS
'---------------------------------------
Dim A() As String 'string array, dynamic
Dim N(0 To 4) As Integer 'integer array, fixed
Dim V As Variant 'pointer to sorted array
Dim i As Integer

A = Split("F,C,A,E,D,B", ",") 'string array, unsorted
For i = 0 To 4: N(i) = 5 - i: Next 'integer array, unsorted

'show unsorted array elements
For i = LBound(A) To UBound(A): Debug.Print A(i);: Next: Debug.Print
For i = LBound(N) To UBound(N): Debug.Print N(i);: Next: Debug.Print
'---------------------------------------



'CLASS OBJECT TO SORT ARRAY
'---------------------------------------
Dim myArray As New clsArray 'new instance class object

'string sample
myArray.GetArray = A 'assign array to object
myArray.Sort 'sort method
V = myArray.GetArray 'return a variant (pointer to sorted array)
For i = LBound(A) To UBound(A): A(i) = V(i): Next 'copy sorted back to original array
For i = LBound(A) To UBound(A): Debug.Print A(i);: Next: Debug.Print

'integer sample
myArray.GetArray = N
myArray.Sort
V = myArray.GetArray
For i = LBound(N) To UBound(N): N(i) = V(i): Next 'copy sorted back to original array
For i = LBound(N) To UBound(N): Debug.Print N(i);: Next: Debug.Print

Set myArray = Nothing 'dispose object, free memory
'---------------------------------------

End Sub



Report
This post has been deleted. Posted by dokken2 on 4 Aug 2011 at 11:07 AM
This post has been deleted.
Report
This post has been deleted. Posted by dokken2 on 4 Aug 2011 at 11:09 AM
This post has been deleted.



 

Recent Jobs