Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg as DWord
Global Words(), Words2() As String
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Remove Dupes", 50,10,100,20
Control Add Button, hDlg, 200,"Remove Dupes", 50,40,100,20
Control Add Button, hDlg, 300,"Remove Dupes", 50,70,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If CB.Msg = %WM_Command AND CB.Ctl = 100 AND CB.Ctlmsg = %BN_Clicked Then
ReDim Words(5)
Array Assign Words() = "a","b","a","b","z","a"
RemoveDupesA
Array Sort Words()
? Join$(Words(),$crlf)
End If
If CB.Msg = %WM_Command AND CB.Ctl = 200 AND CB.Ctlmsg = %BN_Clicked Then
ReDim Words(5), Words2(5)
Array Assign Words() = "a","b","a","b","z","a"
RemoveDupesB
Array Sort Words2()
? Join$(Words2(),$crlf)
End If
If CB.Msg = %WM_Command AND CB.Ctl = 300 AND CB.Ctlmsg = %BN_Clicked Then
ReDim Words(5)
Array Assign Words() = "a","b","a","b","z","a"
Array Sort Words()
RemoveDupesC
? Join$(Words(),$crlf)
End If
End Function
Sub RemoveDupesA '1 array, no sorting
Local iMax,i,j,iResult as Long
iMax = UBound(Words)
For i = 0 to iMax - 1
For j = i+1 To iMax
If Words(i) = Words(j) Then Array Delete Words(j) : Decr iMax
Next j
Next i
ReDim Preserve Words(iMax)
End Sub
Sub RemoveDupesB '2 arrays, no sorting
Local iPos,i,iResult as Long
For i = 0 to UBound(Words)-1
Array Scan Words2(0), Collate Ucase, =Words(i), To iResult
If iResult = 0 Then Words2(iPos) = Words(i) : Incr iPos
Next i
ReDim Preserve Words2(iPos-1)
End Sub
Sub RemoveDupesC '1 array sorted
Local i, iPos As Long
For i = UBound(Words) To 1 Step -1 'zero based array
If Words(i) = Words(i-1) Then Array Delete Words(i) : Incr iPos
Next i
ReDim Preserve Words(UBound(Words)-iPos)
End Sub
'gbs_00574
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm