Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_ButtonNew
IDC_ButtonSort
IDC_ListBox
End Enum
Global hDlg As Dword, D(), DTag() As String
Function PBMain() As Long
Dialog New Pixels, 0, "PowerBASIC",300,300,200,300, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_ButtonNew,"New Data", 10,10,75,25
Control Add Button, hDlg, %IDC_ButtonSort,"Sort", 100,10,50,25
Control Add ListBox, hDlg, %IDC_ListBox,, 10,40,200,240
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local i,iSelected As Long
Static SortDir As Long
Select Case Cb.Msg
Case %WM_InitDialog
CreateData
LoadDToListBox
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_ButtonNew
CreateData
LoadDToListBox
Case %IDC_ButtonSort
Reset DTag()
'set selected element of DTag()
ListBox Get Select hDlg, %IDC_ListBox To iSelected
DTag(iSelected) = "1"
'sort D() and DTag() along with it
SortDir = SortDir Xor 1
If SortDir Then
Array Sort D(), TagArray DTag(), Ascend
Else
Array Sort D(), TagArray DTag(), Descend
End If
'reload ListBox with sorted D()
LoadDToListBox
'select the ListBox item corresponding to the DTab() element that was set
For i = 1 To 15
If DTag(i) = "1" Then ListBox Select hDlg, %IDC_ListBox, i : Exit For
Next i
End Select
End Select
End Function
Sub CreateData
Local i As Long
ReDim D(1 To 15), DTag(1 To 15)
For i = 1 To 15
D(i) = Format$(Rnd(1,99),"00")
Next i
End Sub
Sub LoadDtoListBox
Local i As Long
ListBox Reset hDlg, %IDC_ListBox
For i = 1 To 15
ListBox Insert hDlg, %IDC_ListBox,i, D(i)
Next i
End Sub
'gbs_01229
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm