by Charl du Toit (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 10th December 2002
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Sort a flexgrid by date! Easy with no special coding! MSFlexGrid control does not support sorting by date.
API Declarations
Dim i, j As Integer 'For the FOR loops.
' Paste this code and declerations under a command button's click event,
' form load event or anywhere!
' IMPORTANT: It is assumed that the date format is DD/MM/YYY and the column
' containing the date is 0.
j = 1
For j = 1 To frmMain.FlexMain.Rows - 1
'Get the different parts of the date.
y = Right(frmMain.FlexMain.TextMatrix(j, 0), 4)
M = Mid(frmMain.FlexMain.TextMatrix(j, 0), 4, 2)
d = Left(frmMain.FlexMain.TextMatrix(j, 0), 2)
'Join them as one number in this order: YYYYMMDD.
Cap = y & M & d
'Write the number to the flexgrid.
frmMain.FlexMain.TextMatrix(j, 0) = Cap
Next j
'Set the column and sort the flexgrid in ascending order.
frmMain.FlexMain.Col = 0
frmMain.FlexMain.Sort = flexSortNumericAscending
i = 1
For i = 1 To frmMain.FlexMain.Rows - 1
'Split the number into the different date parts.
y = Left(frmMain.FlexMain.TextMatrix(i, 0), 4)
M = Mid(frmMain.FlexMain.TextMatrix(i, 0), 5, 2)
d = Right(frmMain.FlexMain.TextMatrix(i, 0), 2)
'Join them and insert a "/" between the day, month and year.
Cap = d & "/" & M & "/" & y
'Write the new date to the flexgrid.
frmMain.FlexMain.TextMatrix(i, 0) = Cap
Next i
' That's it!
No comments have been posted about Sort a flexgrid by date! Easy with no special coding! MSFlexGrid control does not support sorting b. Why not be the first to post a comment about Sort a flexgrid by date! Easy with no special coding! MSFlexGrid control does not support sorting b.