#138810 - 2005-04-28 02:05 AM
Converting type string to type date
|
daniel1982
Getting the hang of it
Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
|
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
|
Top
|
|
|
|
#138812 - 2005-04-28 02:52 AM
Re: Converting type string to type date
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
If you change the format of your date text to 2005/04/27 the you can sort it easily.
|
Top
|
|
|
|
#138814 - 2005-04-28 04:17 AM
Re: Converting type string to type date
|
daniel1982
Getting the hang of it
Registered: 2005-03-23
Posts: 77
Loc: Sydney, Australia
|
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]
Edited by NTDOC (2005-04-28 04:41 AM)
|
Top
|
|
|
|
#138817 - 2005-04-28 05:05 AM
Re: Converting type string to type date
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
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
Edited by Howard Bullock (2005-04-28 05:08 AM)
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|