' ColumnSort function
' Tom Lyon
' February 19, 2002
' ain't no copyright here, copy to your heart's content
'
' form requirements -
'
' create sort buttons to use in place of column headers. design of buttons is left up to the reader
' there are three buttons per column, a default, one to indicate ascending order, one to indicate descending order
' the buttons will be hidden and shown to indicate which column is sorted and the order of the sort
' they are named Sort1X, Sort1A, Sort1D ... Sort9X, Sort9A, Sort9D. If there are 3 fields for which to provide sorting
' then 9 buttons are needed. Up to 9 fields (utilizing 27 buttons) may be specified. just one field may be specified
' if desired. button text is not critical
'
' in each button's OnPush event, place the following code:
'
' ColumnSort(numbuttons, left(right(obj(a_form_current).active(),2),1), a_form_current, obj(":" + a_form_current + ":" + obj(a_form_current).active()).tag, right(obj(a_form_current).active(),1))
' it works :)
'
' in calling form's init event, place the following:
'
' dim shared numbuttons as N
' numbuttons = n where n = the number of fields for which to provide a sorting button. this function can accommodate up to 9 sort fields
' setting the button's tag property to the field name to be sorted allows button text to be anything desired
' sort1X.tag = "Technician"
' sort1A.tag = "Technician"
' sort1D.tag = "Technician"
' sort2X.tag = "Date"
' sort2A.tag = "Date"
' sort2D.tag = "Date"
' .
' .
' .
' sort9X.tag = "Date"
' sort9A.tag = "Date"
' sort9D.tag = "Date"
'
function ColumnSort as C(csbuttons as N,csbutton as C,csformname as C,csfieldname as C,csdirection as C)
'
' csbuttons = total number of sort buttons on the form derived from variable in calling form's init event called numbuttons
' csbutton = the "number" of the current button, derived from the actual button object name
' csformname = current form name which called the ColumnSort function
' csfieldname = name of field to be sorted, derived from tag name of button, declared in calling form's init event
' csdirection = direction of impending sort, ascending or descending
'
' function code starts here:
'
for csnumbutton = 1 to csbuttons
csobj = obj(":" + csformname + ":" + "Sort" + alltrim(str(csnumbutton,2,0)) + "D")
csobj.hide()
csobj = obj(":" + csformname + ":" + "Sort" + alltrim(str(csnumbutton,2,0)) + "A")
csobj.hide()
csobj = obj(":" + csformname + ":" + "Sort" + alltrim(str(csnumbutton,2,0)) + "X")
csobj.show()
next
if csdirection = "A" then
csobj = obj(":" + csformname + ":" + "Sort" + csbutton + "D")
csobj.show()
else
csobj = obj(":" + csformname + ":" + "Sort" + csbutton + "A")
csobj.show()
end if
csobj = obj(":" + csformname + ":" + "Sort" + csbutton + "X")
csobj.hide()
' if the embedded browse of the calling form is not named browse1, the follow two lines will need to be changed
' to reflect the actual name of the browse. This function will not work with multiple browses on the same form
' but could easily be made to do so
csobj = obj(":" + csformname + ":browse1:" + csfieldname)
csobj.activate()
csobj = obj(":" + csformname + ":browse1")
' turn on progress message for user, comment out the line below if you are not using a progress message
msg(1, "Sorting..")
if csdirection = "A" then
csobj.quick_sort(.F.)
else
csobj.quick_sort()
end if
' turn off progress message. comment out the line below if you are not using a progress message
msg(0, "")
end function
' Tom Lyon
' February 19, 2002
' ain't no copyright here, copy to your heart's content
'
' form requirements -
'
' create sort buttons to use in place of column headers. design of buttons is left up to the reader
' there are three buttons per column, a default, one to indicate ascending order, one to indicate descending order
' the buttons will be hidden and shown to indicate which column is sorted and the order of the sort
' they are named Sort1X, Sort1A, Sort1D ... Sort9X, Sort9A, Sort9D. If there are 3 fields for which to provide sorting
' then 9 buttons are needed. Up to 9 fields (utilizing 27 buttons) may be specified. just one field may be specified
' if desired. button text is not critical
'
' in each button's OnPush event, place the following code:
'
' ColumnSort(numbuttons, left(right(obj(a_form_current).active(),2),1), a_form_current, obj(":" + a_form_current + ":" + obj(a_form_current).active()).tag, right(obj(a_form_current).active(),1))
' it works :)
'
' in calling form's init event, place the following:
'
' dim shared numbuttons as N
' numbuttons = n where n = the number of fields for which to provide a sorting button. this function can accommodate up to 9 sort fields
' setting the button's tag property to the field name to be sorted allows button text to be anything desired
' sort1X.tag = "Technician"
' sort1A.tag = "Technician"
' sort1D.tag = "Technician"
' sort2X.tag = "Date"
' sort2A.tag = "Date"
' sort2D.tag = "Date"
' .
' .
' .
' sort9X.tag = "Date"
' sort9A.tag = "Date"
' sort9D.tag = "Date"
'
function ColumnSort as C(csbuttons as N,csbutton as C,csformname as C,csfieldname as C,csdirection as C)
'
' csbuttons = total number of sort buttons on the form derived from variable in calling form's init event called numbuttons
' csbutton = the "number" of the current button, derived from the actual button object name
' csformname = current form name which called the ColumnSort function
' csfieldname = name of field to be sorted, derived from tag name of button, declared in calling form's init event
' csdirection = direction of impending sort, ascending or descending
'
' function code starts here:
'
for csnumbutton = 1 to csbuttons
csobj = obj(":" + csformname + ":" + "Sort" + alltrim(str(csnumbutton,2,0)) + "D")
csobj.hide()
csobj = obj(":" + csformname + ":" + "Sort" + alltrim(str(csnumbutton,2,0)) + "A")
csobj.hide()
csobj = obj(":" + csformname + ":" + "Sort" + alltrim(str(csnumbutton,2,0)) + "X")
csobj.show()
next
if csdirection = "A" then
csobj = obj(":" + csformname + ":" + "Sort" + csbutton + "D")
csobj.show()
else
csobj = obj(":" + csformname + ":" + "Sort" + csbutton + "A")
csobj.show()
end if
csobj = obj(":" + csformname + ":" + "Sort" + csbutton + "X")
csobj.hide()
' if the embedded browse of the calling form is not named browse1, the follow two lines will need to be changed
' to reflect the actual name of the browse. This function will not work with multiple browses on the same form
' but could easily be made to do so
csobj = obj(":" + csformname + ":browse1:" + csfieldname)
csobj.activate()
csobj = obj(":" + csformname + ":browse1")
' turn on progress message for user, comment out the line below if you are not using a progress message
msg(1, "Sorting..")
if csdirection = "A" then
csobj.quick_sort(.F.)
else
csobj.quick_sort()
end if
' turn off progress message. comment out the line below if you are not using a progress message
msg(0, "")
end function
Comment