Page 1 of 1 1
Topic Options
#138810 - 2005-04-28 02:05 AM Converting type string to type date
daniel1982 Offline
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
#138811 - 2005-04-28 02:31 AM Re: Converting type string to type date
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
No
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138812 - 2005-04-28 02:52 AM Re: Converting type string to type date
Howard Bullock Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#138813 - 2005-04-28 02:52 AM Re: Converting type string to type date
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11603
Loc: CA
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.

Top
#138814 - 2005-04-28 04:17 AM Re: Converting type string to type date
daniel1982 Offline
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
#138815 - 2005-04-28 04:44 AM Re: Converting type string to type date
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11603
Loc: CA
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.


Edited by NTDOC (2005-04-28 04:45 AM)

Top
#138816 - 2005-04-28 04:50 AM Re: Converting type string to type date
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22343
Loc: OK
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
_________________________
!

download KiXnet

Top
#138817 - 2005-04-28 05:05 AM Re: Converting type string to type date
Howard Bullock Offline
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)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 166 anonymous users online.
Newest Members
dimi575, Drecksnacken, Nlill, webtools321, multiman
17734 Registered Users

Generated in 0.033 seconds in which 0.012 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org