Hi Everyone,
I've got a problem with sorting an array of UDT's that consist
of integers. When the integers are less than 255 they get sorted
correctly, but when they get > 255 they don't sort correctly. I
read somewhere that PB sorts UDT's like strings, so I'm assuming
that what happens is that once I get above 255 I'm creating a nul
that the string sorting algorithm sees as the lowest "character"
and puts it first in the list. Just in case I'm not making any
sense, here's an example:
[code]
#Compile Exe
#Dim All
#Register None
#Include "Win32API.INC"
Type TwoInts
Int1 As Integer
Int2 As Integer
End Type
Function WinMain(ByVal hCurInstance As Long, _
ByVal hPrevInstance As Long, _
lpszCmdLine As Asciiz Ptr, _
ByVal nCmdShow As Long) Export As Long
Dim IntArray(1 To 3) As TwoInts
Dim Counter As Integer
'Init Array:
For Counter = 1 To 3
IntArray(Counter).Int1 = Counter
IntArray(Counter).Int2 = Counter
Next Counter
'Sort Array:
Array Sort IntArray(), From 3 To 4
'Display Expected Results:
MsgBox "Element 1 =" & Str$(IntArray(1).Int1) & Chr$(13) & _
"Element 2 =" & Str$(IntArray(2).Int1) & Chr$(13) & _
"Element 3 =" & Str$(IntArray(3).Int1)
'Change The Value To > &HFF and < &HFF00 So There's A Null:
IntArray(2).Int2 = 256
'Sort Again:
Array Sort IntArray(), From 3 To 4
'Now Look Where The 256 Is:
MsgBox "Element 1 =" & Str$(IntArray(1).Int2) & Chr$(13) & _
"Element 2 =" & Str$(IntArray(2).Int2) & Chr$(13) & _
"Element 3 =" & Str$(IntArray(3).Int2)
End Function
[\CODE]
I understand (at least I think I do) why this is happening, but
is there someway I can keep my UDTs and still sort correctly? If
not, I can bust em' up into three Integer arrays, but that'll be
somewhat of a pain. I looked at the Collate String and that's
a possibility, but I'm not sure I'd have all my bases covered.
Thanks In Advance, folks!!!
------------------
[email protected]
I've got a problem with sorting an array of UDT's that consist
of integers. When the integers are less than 255 they get sorted
correctly, but when they get > 255 they don't sort correctly. I
read somewhere that PB sorts UDT's like strings, so I'm assuming
that what happens is that once I get above 255 I'm creating a nul
that the string sorting algorithm sees as the lowest "character"
and puts it first in the list. Just in case I'm not making any
sense, here's an example:
[code]
#Compile Exe
#Dim All
#Register None
#Include "Win32API.INC"
Type TwoInts
Int1 As Integer
Int2 As Integer
End Type
Function WinMain(ByVal hCurInstance As Long, _
ByVal hPrevInstance As Long, _
lpszCmdLine As Asciiz Ptr, _
ByVal nCmdShow As Long) Export As Long
Dim IntArray(1 To 3) As TwoInts
Dim Counter As Integer
'Init Array:
For Counter = 1 To 3
IntArray(Counter).Int1 = Counter
IntArray(Counter).Int2 = Counter
Next Counter
'Sort Array:
Array Sort IntArray(), From 3 To 4
'Display Expected Results:
MsgBox "Element 1 =" & Str$(IntArray(1).Int1) & Chr$(13) & _
"Element 2 =" & Str$(IntArray(2).Int1) & Chr$(13) & _
"Element 3 =" & Str$(IntArray(3).Int1)
'Change The Value To > &HFF and < &HFF00 So There's A Null:
IntArray(2).Int2 = 256
'Sort Again:
Array Sort IntArray(), From 3 To 4
'Now Look Where The 256 Is:
MsgBox "Element 1 =" & Str$(IntArray(1).Int2) & Chr$(13) & _
"Element 2 =" & Str$(IntArray(2).Int2) & Chr$(13) & _
"Element 3 =" & Str$(IntArray(3).Int2)
End Function
[\CODE]
I understand (at least I think I do) why this is happening, but
is there someway I can keep my UDTs and still sort correctly? If
not, I can bust em' up into three Integer arrays, but that'll be
somewhat of a pain. I looked at the Collate String and that's
a possibility, but I'm not sure I'd have all my bases covered.
Thanks In Advance, folks!!!
------------------
[email protected]
Comment