FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Bug in Harbour Descend()
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Bug in Harbour Descend()
Posted: Mon Oct 17, 2022 02:19 PM
Master Enrico, look this:

http://www.pctoledo.com.br/forum/viewtopic.php?f=4&t=19895

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Mon Oct 17, 2022 02:50 PM

Ok, thank you. I already use that workaround. I was hope that there is a better way.

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 03:23 PM
Please note that this is not working too:

Code (fw): Select all Collapse
DESCEND( DTOS( dDate ) )


I can't believe that this bug has not been corrected yet... :-)
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 05:05 PM
Master Enrico, I'm not sure, but I think you have to save the DATES, in a Database first. Just an idea.

Maestro Enrico, no estoy seguro, pero creo que primero debe guardar las FECHAS en una base de datos. Solo una idea.

Example / ejemplo:

Code (fw): Select all Collapse
    USE Sales NEW
    INDEX ON Str(Descend(SaleDate)) + Salesman TO LastSale
OR

   USE Sales NEW
   INDEX ON Descend(OrdDate) TO SalesDate


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 05:16 PM
It doesn't work either. This works:

Code (fw): Select all Collapse
DESCEND( dDate )


But this not:

Code (fw): Select all Collapse
DESCEND( DTOS( dDate ) )


Please note that there is no problem at all with xHarbour.
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 05:36 PM

? DESCEND( dDate ) // Esto me retorna un numero, está correcto?

Regards, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 05:42 PM

Yes, that's right. The problem is there when you want to combine dates and other data types. In this case you have to convert the dates to strings and here the codepage breaks the sort order of the descending string.

Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 05:45 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 06:04 PM
Thank you. It is not a real solution but better than nothing:

Code (fw): Select all Collapse
DESCEND( STR( nVal ) ) => STR( 999999999999999 - nVal )
DESCEND( DTOS( dVal ) ) => STR( DESCEND( dVal ) )


Let's hope that Harbour developers will fix the bug, one day or another...

My concern is that Descend() could be called millions of times during a sort. So it should be as faster as possible.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 06:23 PM
From Harbour-users group

DESCEND() function is designed to operate on binary (BYTE) sorting
and gives reverted collation order only for codepages which use
such collation.

Because DESCEND() converts numbers to characters which have
special order in CP you are using. Look at this list archive
for some easy to create custom DESCEND() replacements which
can be used with non accented Latin based languages like
Lithuanian or Polish ones.


Dear Enrico
Please try with this. I hope you find this codepage useful
Code (fw): Select all Collapse
REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN, HB_CODEPAGE_IT850

HB_CDPSELECT( "IT850" )
hb_langSelect( 'IT' )
// hb_SetTermCP( 'ITWIN', 'ITWIN', .T. )   // Also with it run ok
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Tue Oct 18, 2022 09:24 PM
It doesn't work, it creates a file with the wrong name. Please try this:

Code (fw): Select all Collapse
#include "Fivewin.ch"


REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN, HB_CODEPAGE_IT850


FUNCTION MAIN()

    HB_CDPSELECT( "IT850" )
    HB_LANGSELECT( "IT" )

    HB_SETTERMCP( "ITWIN", "ITWIN", .T. )

    MEMOWRIT( "àèéìòù.txt", "àèéìòù" )

    RETURN NIL
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Bug in Harbour Descend()
Posted: Wed Oct 19, 2022 12:52 AM
Enrico Maria Giordano wrote:It doesn't work, it creates a file with the wrong name. Please try this:

Code (fw): Select all Collapse
#include "Fivewin.ch"


REQUEST HB_LANG_IT
REQUEST HB_CODEPAGE_ITWIN, HB_CODEPAGE_IT850


FUNCTION MAIN()

    HB_CDPSELECT( "IT850" )
    HB_LANGSELECT( "IT" )

    HB_SETTERMCP( "ITWIN", "ITWIN", .T. )

    MEMOWRIT( "àèéìòù.txt", "àèéìòù" )

    RETURN NIL


Sorry Enrico, but the example you put now has nothing to do with the Descend() function
Has the example I posted worked?
I will look at the new example you propose and I will answer you
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Wed Oct 19, 2022 07:52 AM

The problem is: without any codepage settings (ie. EN codepage) Descend() is fine but accented chars from filesystem are wrong. With ITWIN (or other codepages I tried) the accented chars from filesystem are right but Descend() is not working.

Any solutions will make me happy. :-)

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Bug in Harbour Descend()
Posted: Wed Oct 19, 2022 08:06 AM
Enrico Maria Giordano wrote:The problem is: without any codepage settings (ie. EN codepage) Descend() is fine but accented chars from filesystem are wrong. With ITWIN (or other codepages I tried) the accented chars from filesystem are right but Descend() is not working.

Any solutions will make me happy. :-)


This is more simple

Code (fw): Select all Collapse
#include "Fivewin.ch"

FUNCTION MAIN()

    LOCAL aData[ 7 ]

    LOCAL i


    HB_SETCODEPAGE( "UTF8" )

    aData[ 1 ] = { "TEST1", 3107.77 }
    aData[ 2 ] = { "TEST2", 852.07 }
    aData[ 3 ] = { "TEST3", 191.00 }
    aData[ 4 ] = { "TEST4", 148.68 }
    aData[ 5 ] = { "TEST5", 44.73 }
    aData[ 6 ] = { "TEST6", 15.24 }
    aData[ 7 ] = { "TEST7", 255.65 }

    ASORT( aData, , , { | aItem1, aItem2 | Descend( Str( aItem1[ 2 ], 10, 2 ) ) + aItem1[ 1 ] < Descend( Str( aItem2[ 2 ], 10, 2 ) ) + aItem2[ 1 ] } )

    xBrowse( aData )

    hb_MemoWrit( "àèéìòù.txt", "àèéìòù" )


    RETURN NIL
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo

El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Bug in Harbour Descend()
Posted: Wed Oct 19, 2022 08:26 AM
Sorry, it doesn't work:

Code (fw): Select all Collapse
? hb_MemoWrit( "àèéìòù.txt", "àèéìòù" )


Result:

Code (fw): Select all Collapse
.F.


:-)