Strange problem sorting a dbf file

Strange problem sorting a dbf file

Postby Marco Turco » Thu Jun 12, 2008 9:24 am

Hi,
I have a really strange problem when I try to sort a dbf file using the command SORT ON .

In this self-contained sample
www.softwarexp.co.uk/beta/browse.zip
I create a new dbf (date ordered) form a source dbf but the order is incorrect (see www.softwarexp.co.uk/beta/browse.gif)

Any ideas ? Thanks in advance.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby Otto » Thu Jun 12, 2008 10:26 am

Marco, I think you mixed up long and short date format.
Regards,
Otto

Image
User avatar
Otto
 
Posts: 6133
Joined: Fri Oct 07, 2005 7:07 pm

Postby Marco Turco » Thu Jun 12, 2008 10:48 am

Hi Otto,
the date values seem to be corrected.

Image

Which dbf editor are you using ?
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby Enrico Maria Giordano » Thu Jun 12, 2008 12:22 pm

I confirm what Otto has found.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8408
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Marco Turco » Thu Jun 12, 2008 1:32 pm

Hi Enrico,
How did you check the dates ?

I checked them using the Norton Commander dbview and the Open Office "Calc" and all displayed well.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby Otto » Thu Jun 12, 2008 1:35 pm

Marco, try your code with
SET CENTURY ON
Regards,
Otto

#include "FiveWin.ch"

function Main()
set century on
set date french

use testm

sort on lb02/a to results
use

USE results

Browse()

USE

return nil
User avatar
Otto
 
Posts: 6133
Joined: Fri Oct 07, 2005 7:07 pm

Postby mmercado » Thu Jun 12, 2008 2:00 pm

Enrico Maria Giordano wrote:I confirm what Otto has found.

Hi Marco:

Certainly you have a mixture of date formats, try this to fix your database:

Use Test
Replace lb02 With CtoD( DtoC( lb02 ) ) All

Regards.

Manuel Mercado
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Postby Enrico Maria Giordano » Thu Jun 12, 2008 2:53 pm

Marco Turco wrote:Hi Enrico,
How did you check the dates ?

I checked them using the Norton Commander dbview and the Open Office "Calc" and all displayed well.


I'm using my own EMAG Software DBU:

http://www.emagsoftware.it/gratis.htm

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8408
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Marco Turco » Fri Jun 13, 2008 8:39 am

Yes, it was a date issue.

I was unable to detect it due the fact that my (very very old) Norton Commander dbView displayed those dates exactly.

Thanks to all for the support.
Best Regards,

Marco Turco
SOFTWARE XP LLP
User avatar
Marco Turco
 
Posts: 858
Joined: Fri Oct 07, 2005 12:00 pm
Location: London

Postby E. Bartzokas » Wed Jun 25, 2008 2:47 pm

Marco Turco wrote:Yes, it was a date issue.

I was unable to detect it due the fact that my (very very old) Norton Commander dbView displayed those dates exactly.

Thanks to all for the support.


Marco hi,
It's one of the best practices to use CENTURY ON, in other words, to
use the format dd/mm/yyyy, thus, you will avoid problems with some
centuries that don't exist any more (or are not usable), such as 0007
vice 2007 !
You can use in your main program at the entry point along with the
SET DATE .... (e.g. ITALIAN), SET EPOCH TO ...
here's an example of what I use...
SET DATE BRITISH
SET EPOCH TO 1980
SET CENTURY ON
When users are lazy and type only the two last digits of a year, e.g.
"31/12/07", the program automatically converts it to "31/12/2007"
and not into "31/12/0007".

Another problem fixed below, is for displaying date fields in the browser
(e.g. TWBROWSE, or XBROWSE), with this method...


Code: Select all  Expand view
        REDEFINE LISTBOX oLbx1 FIELDS ;
                     PADC(History->STATUS,3)  ,;    // STATUS "S" or blank
               Right(History->HISTNUMB,5) , ;       // Autom.number
               Right(History->FILENUMB,6) , ;       // File number
     SCTOC(DTOC(StoD(History->HISTDATE))) , ;       // Date (dd-mm-yy)
.....
                   HEADERS  "St."          ,;
                           "Hist"        ,;
                           "File"        ,;
                           "Off.Date"     ,;



The function SCTOC(...) converts the year into two digits thus, gaining
some width in the browser. Here's the function.

Code: Select all  Expand view
Function SCTOC(x)
*---------------- Returns a date (Char type) from 10 chars to 8 chars (Sort)
* SCTOC(DTOC(StoD(History->HISTDATE))),;         // Date (dd-mm-yy)
   Local z := ""

   if len(x) == 8
      Return (x)
   endif
   z := left(x, 6)  +;  // 18-01-2003
        right(x,2)
   Return (z)


Kind regards
Evans
ps. I hope it helps you a little...
User avatar
E. Bartzokas
 
Posts: 114
Joined: Tue Feb 14, 2006 8:13 am
Location: Corinth, Greece


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 138 guests