Page 1 of 1

Indexing by the specified field

Posted: Tue May 30, 2017 9:30 pm
by Eugene Lutsenko
Hi!

I would like to sort the table by field name (or number) which is set as a variable value.

Now used this option:
INDEX ON STR(99999999.9999999-FIELDGET(ff),19,7) TO Mrk_funi

But it turned out that it doesn't work for numeric fields that specify the integer values 0 and 1. In the other cases it works fine.
Sort numeric integer error does not cause, but the result is wrong.

Tried this:
mFN = FIELDNAME(ff)
INDEX ON STR(99999999.9999999-&mFN,19,7) TO Mrk_funi

But it throws error.

And such a simple option is also not working:
INDEX ON STR(99999999.9999999-FIELDNAME(ff),19,7) TO Mrk_funi

The data type in the field numeric N7

Error occurs when a field numeric integer. if you make the decimals no zeros, then everything is working fine.

Which In Alaska is the data types for databases: the "Integer" and "Short integer"?

Re: Indexing by the specified field

Posted: Wed May 31, 2017 1:05 am
by skiman
Hi,

You can use a function for this.

Code: Select all

INDEX ON STR(99999999.9999999-FIELDGET(ff),19,7) TO Mrk_funi
You can change this to:

Code: Select all

INDEX ON calculatevalue(ff) TO Mrk_funi
In the function you can controle everything.

Code: Select all

function calculatevalue(ff)
local nValue := fieldget(ff)
if nValue
...
else
....
endif
return STR(99999999.9999999-nValue,19,7) 

Re: Indexing by the specified field

Posted: Wed May 31, 2017 4:48 am
by Eugene Lutsenko
Thank you very much! Based on this, I did what I need, and everything works fine:

Code: Select all

FUNCTION CalculateValue(ff)
local nValue := FIELDGET(ff)

mKey = ''

IF FIELDDECI(ff) = 0                    // Целые
   mKey = STR(99999999-nValue,15)
ELSE
   mKey = STR(99999999.9999999-nValue,15,7)
ENDIF

RETURN(mKey)