-
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?
-
Probably because you are not filling the last entry in the array. When you fill the array I bet you are doing it to Ubound - 1 when you should be using Ubound.
-
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]
-
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