A while back there was a discussion of Tag Arrays and sorting. I've used a Typed array to sort multiple fields with for so long I'd pretty much forgotten about Tag arrays. Anyway, here's a real life example of using a Typed Array to sort for any who may not be familiar with the practice.
It should be relatively easy to follow (I think).
Hope this clears any confusion any may have about sorting multiple fields of info.
===================================================
"I'm not going to get into the ring with Tolstoy."
Ernest Hemingway (1899-1961)
===================================================
It should be relatively easy to follow (I think).
Code:
'******************************************************* ' I use the method below to sort data according to related fields. ' Instead of using Tag Arrays to "subsort" identical items, ' a Sort field in a Typed array is much easier. ' Very simple, fast and easy to follow in coding '******************************************************* ' ' Sub Sort_By is called from a CallBack function. ' Sort_key is the button clicked to Call Sort_By in the Callback ' ''' 'typed data used in this example set at top of program 'Type xx03 'Check_Record ' SortBy As String * 60 'plenty room for sorting in this case ' Date As Long ' Nam As String * 24 ' Number As Long ' Amount As Currency ' ... more stuff here not needed for example 'End Type ' Global Checks_Display_List() As xx03 'array that holds the data ' Sub Sort_by(Sort_Key As Long) Common_Locals 'more convenient to store frequently used Local variables than ' Static Sorted_By_Last_Flag As Long ' 'now assign sort - For ctr = LBound(Checks_Display_List()) To UBound(Checks_Display_List()) Select Case Sort_Key ' Case Btn_Id&(10) 'Entry order ' s$ less cluttered than using full array name in each statement s$ = Using$("######## ", Checks_Display_List(ctr).Record_Number) ' Case Btn_Id&(11) ' "Date" s$ = Using$("######## ", Checks_Display_List(ctr).Date) & _ Checks_Display_List(ctr).Nam ' Case Btn_Id&(12) 'Checknumber s$ = Using$("######## ", Checks_Display_List(ctr).Number) & _ Using$("######## ", Checks_Display_List(ctr).Amount) & _ Checks_Display_List(ctr).Nam ' Case Btn_Id&(13)'Name s$ = Checks_Display_List(ctr).Nam & _ Using$("######## ", Checks_Display_List(ctr).Date) & _ Using$("######## ", Checks_Display_List(ctr).Amount) Case Btn_Id&(14)'Amount s$ = Using$("######## ", Checks_Display_List(ctr).Amount) & _ Checks_Display_List(ctr).Nam ' Case Btn_Id&(15)'"Category" s$ = Checks_Display_List(ctr).Category & _ Checks_Display_List(ctr).Nam & _ Using$("######## ", Checks_Display_List(ctr).Amount) ' Case Btn_Id&(16)'"SubCategory" s$ = Checks_Display_List(ctr).SubCategory & _ Checks_Display_List(ctr).Nam & _ Using$("######## ", Checks_Display_List(ctr).Amount) ' Case Btn_Id&(17): '"Reason" s$ = Checks_Display_List(ctr).Reason & _ Using$("######## ", Checks_Display_List(ctr).Amount) ' End Select Checks_Display_List(ctr).SortBy = s$ 'fields to sort by inserted Next ctr 'reverse sort if same sort button clicked again If Sorted_By_Last_Flag = Sort_Key Then Array Sort Checks_Display_List(), Descend Reset Sorted_By_Last_Flag 'so as to be able to reverse again Else Array Sort Checks_Display_List() 'Ascending order Sorted_By_Last_Flag = Sort_Key 'set so to reverse if same sort button is clicked End If ' .. lots more code here not necessary for the example
===================================================
"I'm not going to get into the ring with Tolstoy."
Ernest Hemingway (1899-1961)
===================================================
Comment