Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
%IDC_Button = 500
Global hDlg As Dword
Global qFreq, qStart, qStop As Quad
Type AdvancedPlan
desc As StringZ * 100
age As StringZ * 15
int As StringZ * 15
inf As StringZ * 15
altinf As StringZ * 15
lumpinc As StringZ * 15
socsec As StringZ * 15
workinc As StringZ * 15
otherinc As StringZ * 15
lumpexp As StringZ * 15
exp As StringZ * 15
altexp As StringZ * 15
End Type
Global tempPlan() As AdvancedPlan
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Test", 20,10,120,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
QueryPerformanceFrequency qFreq
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
Local i,j As Long
For j = 100 To 1000 Step 100
ReDim tempPlan(j)
For i = 0 To UBound(tempPlan) : tempPlan(i).age = Str$(Rnd(1,10000)) : Next i
QueryPerformanceCounter qStart : JGSort : QueryPerformanceCounter qStop
? "UBound:" + Str$(j) + " " + Format$((qStop-qStart)/qFreq,"###.000") & " seconds" '+ $crlf + ShowResults
Next j
End Select
End Select
End Function
Sub MelSort
Local x,i,L As Long
For x = 1 To UBound(tempPlan)
L = x
Do Until Val(tempPlan(L).age) <= Val(tempPlan(L-1).age) Or L = 0
Swap tempPlan(L), tempPlan(L-1)
Decr L
Loop
Next x
End Sub
Sub JGSort 'insertion sort
Local j,ii,Upper As Long, xs As AdvancedPlan, vxs As Long
UPper = UBound(tempPlan)
For ii = 0 To (Upper - 1)
xs = tempPlan(ii) : vxs = Val(tempPlan(ii).age) : j = ii
While (j > 0) And (Val(tempPlan(j-1).age) > vxs)
tempPlan(j) = tempPlan(j-1) : Decr j
Wend
tempPlan(j) = xs
Next
End Sub
Sub BubbleSort 'custom SWAP built in
Local i,j,vi As Long, temp As AdvancedPlan
For i = 1 To UBound(tempPlan)-1
vi = Val(tempPlan(i).age)
For j = i+1 To UBound(tempPlan)
If vi > Val(tempPlan(j).age) Then
temp = tempPlan(i)
tempPlan(i) = tempPlan(j)
tempPlan(j) = temp
End If
Next j
Next j
End Sub
Sub PierreSort 'custom SWAP built in
Local lower, upper, i,j,vi As Long, temp As AdvancedPlan
Lower = LBound(tempPlan) : Upper = UBound(tempPlan)
For i = Lower To Upper-1
vi = Val(tempPlan(i).age)
For j = i+1 To UPper
If vi > Val(tempPlan(j).age) Then
temp = tempPlan(i)
tempPlan(i) = tempPlan(j)
tempPlan(j) = temp
End If
Next j
Next j
End Sub
Function ShowResults() As String
Local temp$, i As Long
For i = 0 To UBound(tempPlan)
temp$+= tempPlan(i).age + $CrLf
Next i
Function = temp$
End Function
Sub MCMSort
Local i As Long
Dim K(UBound(tempPlan)) As Long
For i = LBound(K) To UBound(K) : K(i) = Val(tempPlan(i).age) : Next i
Array Sort K(), TagArray tempPlan()
End Sub
Sub MikeSort
Local sMask As String, x As Long
sMask = String$(Int(Log10(UBound(tempPlan)) + 1),"#")
For x = LBound(tempPlan) To UBound(tempPlan()) : tempPlan(x).age += Using$(sMask,x) : Next
Array Sort tempPlan()
For x = LBound(tempPlan) To UBound(tempPlan) : tempPlan(x).age = Left$(tempPlan(x).age,Len(tempPlan(x).age)-Len(sMask$)) : Next
End Sub
http://www.garybeene.com/sw/gbsnippets.htm