Results 1 to 4 of 4

Thread: Algorithm?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    TempUBound = UBound(vArray)
    TempLBound = LBound(vArray)

    starttime = Timer

    Do
    bSorted = True

    For j = TempLBound To TempUBound - 1

    If vArray(j) > vArray(j + 1) Then

    TestElemFirst = vArray(j)
    TestElemNext = vArray(j + 1) 'getting a "null value" in array why?

    vArray(j) = TestElemNext
    vArray(j + 1) = TestElemFirst

    bSorted = False

    End If

    Next j


    Loop While bSorted = False

    Form1.Text1.Text = Timer - starttime

    SortArray = vArray
    any ideas why the result array has a null in it?
    Don't go away mad, just go away.

    Bam-Bam

  2. #2

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Lost in the Mojave Desert
    Posts
    82
    i get out of script error, but i did find the problem i was creating an array with a base of 1 not 0 so created an array with a base of 0 and that solved the problem but i need to code so that regardless of the base it will still act appropriatly, but then again use of the Option base 1 is unusual, tnx
    i put ubound-1 because im comparing one element with the next element and if i didnt do -1 i would get a out of script error

    [Edited by Bam_BamIR on 12-11-2000 at 04:15 PM]
    Don't go away mad, just go away.

    Bam-Bam

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Since the Option Base statement only affects the lower bound of arrays, you could do something like this and use MyLowerBound for the lower bound value of all arrays.
    Code:
        Dim AnyArray(3) As Integer
        
        On Error Resume Next
        If AnyArray(0) = 1 Then
            If Err.Number = 9 Then
                'MsgBox "base is 1"
                MyLowerBound = 1
                Err.Clear
            Else
                MyLowerBound = 0
            End If
        End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width