Access 2007, not recoginizing Array.Sort - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Access 2007, not recoginizing Array.Sort

jritchiejritchie Posts: 1Member
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.

Comments

  • dokken2dokken2 Posts: 532Member
    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



  • dokken2dokken2 Posts: 532Member
    This post has been deleted.
  • dokken2dokken2 Posts: 532Member
    This post has been deleted.
Sign In or Register to comment.