Re: VB6 LISTBOX problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



inline...

"Larry Serflaten" <serflaten@xxxxxxxxxxxxxx> wrote in message
news:uY05Je4EIHA.3980@xxxxxxxxxxxxxxxxxxxxxxx


Not very quick on my machine (733 MHz). It took about 12
seconds. Here's a QuickSort method that pulls the data out
of your array, sorts it, then puts the sorted data back into your
array, in under 2 seconds....

Well under 1 sec on my 21st century box. :)

' Pull the data out
Sorted = String((UB - LB + 1) * 6, "*")
ofs = 1
For idx = LB To UB
Mid(Sorted, ofs, 1) = MyType(idx).AString1
Mid(Sorted, ofs + 1, 4) = Format$(MyType(idx).ANum, "0000")
Mid(Sorted, ofs + 5, 1) = MyType(idx).AString2
ofs = ofs + 6
Next

I love this concept. It would not have occurred to me to build a single string
representing the entire array, but as each element is a fixed length, it makes
perfect sense. The notion of then sorting the 6 char elements of the single
string is excellent, and avoids the noise of 47,000 separate string allocations.


If up <= dn Then
If up < dn Then
temp = Mid$(Sorted, dn, 6)
Mid(Sorted, dn, 6) = Mid$(Sorted, up, 6)
Mid(Sorted, up, 6) = temp
End If
up = up + 6
dn = dn - 6
End If


Others may not care, but it has always bothered me that many implementations of
the quick sort do not put the additional test "If up < dn" around the swap.
Allowing it to swap when up = dn just seems wrong to me, and I'm glad to see
some one else cares enough to give their very best. :)


.



Relevant Pages

  • about the efficiency of arrays of strings versus very long strings
    ... There is all sorts of data in them, ... I am curious because I'm assuming that labview can't work out how much memory it'll need for an array of string, as each element can be of different length. ...
    (comp.lang.labview)
  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)