Help

Source code related resources

Moderator: Rathinagiri

Post Reply
zorpavns
Posts: 16
Joined: Tue Apr 23, 2013 10:43 am
DBs Used: DBF
Location: Novi Sad, Serbia
Birthday

Help

Post by zorpavns » Sun Feb 18, 2018 12:44 pm

Help
How to index positive and negative numbers. So put them in a rising order.

When the number is converted to a string, it disappears like this:

-10000.00
20000.00
-5000.00
5000.00
Does anyone have an idea of ​​how to fit properly.

Thanks in advance

Marin
Posts: 30
Joined: Tue Dec 20, 2016 1:39 pm
DBs Used: DBF
Location: Bulgaria, Sofia
Has thanked: 32 times
Been thanked: 4 times
Contact:

Post by Marin » Sun Feb 18, 2018 12:56 pm

Hi zorpavns,

Try using:
INDEX ON VAL(char_field) to File_NTX.

Regards,
Marin

zorpavns
Posts: 16
Joined: Tue Apr 23, 2013 10:43 am
DBs Used: DBF
Location: Novi Sad, Serbia
Birthday

Post by zorpavns » Sun Feb 18, 2018 12:58 pm

What to do when a combined index is composed of letters and numbers

Marin
Posts: 30
Joined: Tue Dec 20, 2016 1:39 pm
DBs Used: DBF
Location: Bulgaria, Sofia
Has thanked: 32 times
Been thanked: 4 times
Contact:

Post by Marin » Sun Feb 18, 2018 1:20 pm

zorpavns wrote:
Sun Feb 18, 2018 12:58 pm
What to do when a combined index is composed of letters and numbers
Please kindly give an example of your index key resulting data. Up to now we were talking about numbers only, i guess...

zorpavns
Posts: 16
Joined: Tue Apr 23, 2013 10:43 am
DBs Used: DBF
Location: Novi Sad, Serbia
Birthday

Post by zorpavns » Sun Feb 18, 2018 1:32 pm

Example index

vrs=Ch2
Sal=Numeric 19,2

vrs+str(sal,19,2)

trmpluym
Posts: 224
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 5 times
Been thanked: 18 times

Post by trmpluym » Sun Feb 18, 2018 1:34 pm

Zorpavns,

There is a simple solution for this problem. You can simply add a large number to compensate the largest possible negative number.

For example when the field has got 4 positions add 99999 (five times 9).

STR(NumField+99999)

The index would be always positive and the sort order is correct.

Theo

ROBROS
Posts: 99
Joined: Thu May 25, 2017 6:30 pm
DBs Used: DBF
Has thanked: 39 times
Been thanked: 7 times

Post by ROBROS » Sun Feb 18, 2018 1:43 pm

Hi Zorpavns,

"Mixed" index: persnr is a "C", character field, date is "D", date field.

My index: index on persnr+dtos(date) to indexfile.

Regards
Robert

edk
Posts: 304
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 82 times
Been thanked: 233 times

Post by edk » Sun Feb 18, 2018 2:56 pm

Try instead of str () to use a strzero ()

User avatar
BeGeS
Posts: 116
Joined: Fri Jul 14, 2017 10:45 am
DBs Used: DBF
Location: La Mancha, Spain
Has thanked: 29 times
Been thanked: 21 times

Post by BeGeS » Sun Feb 18, 2018 3:14 pm

I would create this function:

Code: Select all

FUNCTION NEGATEX(NUMERO)
LOCAL RESUL
 IF NUMERO<0
    RESUL:= "-" + STR(ABS(NUMERO),18,2)
 ELSE
    RESUL:= STR(NUMERO,19,2)
 ENDIF
RETURN RESUL
Your index:

vrs+NEGATEX(sal)
I get by with a little help from my friends

Post Reply