daniel1982
(Getting the hang of it)
2005-04-28 02:05 AM
Converting type string to type date

Hello all,

I have inherited some code from a collegue, which uses a GUI interface. One part of the GUI contains a list of files in a table. One of the columns in the table contains the last time the files were modified. My problem is when I click on the name of the column to sort the files by date, the files are not being sorted correctly.

I'm assuming this is because Kix is simply sorting as if it was a line of text (so 1/04/2005 4:07:56 PM comes before 15/02/2005 8:43:24 AM), and not a date. Is there any easy way to tell Kix that this field is a date and should be sorted accordingly?

Thanks for your help,
Regards,
Daniel


Les
(KiX Master)
2005-04-28 02:31 AM
Re: Converting type string to type date

No

Howard Bullock
(KiX Supporter)
2005-04-28 02:52 AM
Re: Converting type string to type date

If you change the format of your date text to 2005/04/27 the you can sort it easily.

NTDOCAdministrator
(KiX Master)
2005-04-28 02:52 AM
Re: Converting type string to type date

Hi Daniel,

I'm assuming it is KiXforms you're speaking of, and if so you could CODE it to sort different ways, but nothing that I'm aware of that is automatic.

What version of KiXtart and are we talking about a KiXform GUI app here?

Please post what version of KiXtart you're using and what the application GUI is written in.

Then if it is in KiXtart you can post the code so that we can review what it is you're even talking about.

There is no guarantee that anyone will have a quick or easy answer for you, but without seeing the actual code it makes it very difficult to help you too.


daniel1982
(Getting the hang of it)
2005-04-28 04:17 AM
Re: Converting type string to type date

Hi NTDOC,

Thanks for your quick reply...The version of KiX that I am using is 4.22 and I am also using KiXForms to create the GUI. I've included the relevant code below:

Code:
 Initialise()

Function Initialise()
$=InitBackupList()
$Form.Show
$=ListLocalProfile()
EndFunction

$System = CreateObject("Kixtart.System")

$Form = $System.Form()
$Form.FormBorderStyle = 1
$Form.Size = 640,480
$Form.MaximizeBox = "False"
$Form.StartPosition = 1
$Form.Text = "Profile Migration Utility (version 1.0)"
$Form.OnAbout = "About"

$tabControl = $Form.Controls.TabControl()
$tabControl.Size = 633, 320
$tabControl.Location = 0, 90

$tabBackup = $tabControl.TabPages.Add
$tabBackup.Size = 626,296
$tabBackup.Location = 4,22
$tabBackup.Text = "Backup"

$lstBackup = $tabBackup.Controls.ListView()
$lstBackup.Size = 500, 200
$lstBackup.Location = 20,70
$lstBackup.CheckBoxes = True
$lstBackup.GridLines = True
$lstBackup.OnDoubleClick = "OnClickSelectBackupItem()"
$lstBackup.OnMouseUp = "OnCheckSelectBackupItem()"
$lstBackup.OnKeyDown = "OnCheckSelectBackupItem()"


; *************************************************************************
; * Backup Functions
; *************************************************************************

Function InitBackupList()
$lstBackup.Clear
;-- Add the columns to the listview
$colProfile = $lstBackup.Columns.Add("Profile", 120)
$colDate = $lstBackup.Columns.Add("Date Last Modified", 150)
$colSize = $lstBackup.Columns.Add("Size (KB)", 100)
$colStatus = $lstBackup.Columns.Add("Status", 100)
EndFunction

Function ListLocalProfile()
Dim $ProfileName, $AccessDate, $FolderSize
$lblWaitBackup.Visible = True
$lstBackup.Visible = False

$lstBackup.Items.Clear
$ProfileName = Dir($PROFILELIST_PATH)
While $ProfileName <> "" And @ERROR = 0
If $ProfileName <> "Aunty" AND $ProfileName <> "All Users" AND $ProfileName <> "Default User" +
AND $ProfileName <> "Administrator" AND $ProfileName <> "." AND $ProfileName <> ".." AND +
$ProfileName <> "LocalService" AND $ProfileNAme <> "NetworkService" AND $ProfileName <> "wsinstall" +
AND $ProfileName <> @USERID
$AccessDate = fnGetFolderProp($PROFILELIST_PATH + "\" + $ProfileName, "DateLastModified")
$FolderSize = fnGetFolderProp($PROFILELIST_PATH + "\" + $ProfileName, "Size") / 1024
AddToBackupList($ProfileName, $AccessDate, $FolderSize)
EndIf
$ProfileName = Dir()
Loop

$lblWaitBackup.Visible = False
$lstBackup.Visible = True
EndFunction

Function fnGetFolderProp($sFldr,$sProp)
Dim $objFSO, $objFldr, $nul
$objFSO = CreateObject("Scripting.FileSystemObject")
If Not VarType($objFSO)=9 Exit 1 EndIf
$objFldr = $objFSO.GetFolder($sFldr)
If Not VarType($objFldr)=9 Exit 3 EndIf
$nul=Execute("$$fnGetFolderProp = $$objFldr."+$sProp)
If VarType($fnGetFolderProp)=0 Exit 87 EndIf
EndFunction


Function AddToBackupList($ProfileName, $ModifiedDate, $FolderSize)
$Item = $lstBackup.Items.Add
$Item.SubItems(0).Text = $ProfileName
$Item.SubItems(1).Text = $ModifiedDate
$Item.SubItems(2).Text = $FolderSize
$Item.SubItems(3).Text = "Selected"
$Item.Checked = True
EndFunction



Cheers,
Daniel

[post modified by NTDOC to remove long lines]


NTDOCAdministrator
(KiX Master)
2005-04-28 04:44 AM
Re: Converting type string to type date

Daniel,

Did not do an extensive review of the code by looks like this snippet of code here needs to be modified as Howard B. said so that the format is stored more like the Europeans do their format. As you see the method Americans use is not very computer friendly for sorting.

YYYY/MM/DD

$colDate = $lstBackup.Columns.Add("Date Last Modified", 150)


There are UDFs to help do that too, but if you need further assistance please let us know.


LonkeroAdministrator
(KiX Master Guru)
2005-04-28 04:50 AM
Re: Converting type string to type date

and you always have the option to fire "onSort"
shawn, do we have this already?

if yes, then you can indeed go and code a nice background snippet for sorting it properly


Howard Bullock
(KiX Supporter)
2005-04-28 05:05 AM
Re: Converting type string to type date

First, please break your LONG line as it make reading and replying very difficult.

Change this line:

$AccessDate = fnGetFolderProp($PROFILELIST_PATH + "\" + $ProfileName, "DateLastModified")

to:
Code:
$AccessDate = fnGetFolderProp$PROFILELIST_PATH + "\" + $ProfileName, "DateLastModified")
$aAccessDate = split($AccessDate)
$aDate = split($aAccessDate[0],"/")
$aTime = split($aAccessDate[1],":")
$aTime[0] = IIF($aAccessDate[2]="PM", (12+$aTime[0]), $aTime[0])
$AccessDate = $aDate[2] + "/" + PadStr($aDate[1],"0",2) + "/" + PadStr($aDate[0],"0",2) + " " + join($aTime, ":")


This alter your date time from:
4/27/2005 10:31:08 PM
to:
2005/27/04 22:48:52

which should be sortable for you.

You will also need PadStr().
Code:
;FUNCTION         PadStr($Input,$Pad,$Length)
;
;AUTHOR Howard A. Bullock (habullock@comcast.net)
;
;ACTION Left pad or Right pad a string with specified characters.
;
;SYNTAX PadStr($Input,$Pad,$Length)
;
;PARAMETERS $Input (Required) - String value
; $Pad (Required) - String value
; $Length (Required) - Integer (Max length of padded string)
; $PadSide (Optional) - String [L|R] Default is "L"
;
;REMARKS The $Pad can be one or more characters. If the Padding exceeds
; the specified maximum length then the resulting string is trimmed
; preserving the original data.
;
;RETURNS String
;
;DEPENDENCIES KiXtart 4.02
;
;EXAMPLES PadStr("401","0",8) result "00000401"
; PadStr("401","0",8,"R") result "40100000"
;
Function PadStr($Input, $Pad, $Length, optional $PadSide)
Dim $i, $x
$PadStr = ""
$Input = "" + $Input
$Pad = "" + $Pad
$Length = 0 + $Length
If $PadSide="" or Len($PadSide)>1 or Instr("LR",$PadSide)= 0
$PadSide = "L"
Endif

$x = Len($Input)

For $i=$x to $Length - 1 Step Len($Pad)
If $PadSide = "L"
$Input = $Pad + $Input
Else
$Input = $Input + $Pad
Endif
Next
If $PadSide = "L"
$Input = Right($Input, $Length)
Else
$Input = Left($Input, $Length)
Endif
$PadStr = $Input
Exit 0
Endfunction