Page 1 of 1
Seek Option
Posted: Tue Mar 15, 2016 6:09 am
by omni
Roger,
We have a user that enters a ref in their system on large files. It is normally something like 000038448. When searching using the standard index for this ref it is an issue because of the leading zeroes as many users do not enter the right number of them. They want a method to find the base (in this case 38448) on the search. Right now it is in a standard autoseek by right clicking the header with that index open. They have 3 or 4 autoseek field options on that inquiry, not just that one. Fairly large file, half million records. I know I could create another numeric field they could use that would hold the same data, but did not want to do that if there is another option.
thanks
Fred
Omni
Re: Seek Option
Posted: Tue Mar 15, 2016 6:30 am
by rdonnay
If you don't want to use a numeric index then I don't know how to help you unless you can confirm that all ref numbers start with 0's in the database.
If that is true, then you can fill in the missing 0's in the value you are seeking.
Re: Seek Option
Posted: Tue Mar 15, 2016 6:47 am
by skiman
Hi,
When you do a seek on padl( cSeek,9,"0") ?
Or:
if(left(cSeek,1)$"0123456789",padl(cSeek,9,"0"),cSeek)
In that case the padl() is only used when the seek started with a number.
Re: Seek Option
Posted: Tue Mar 15, 2016 7:11 am
by Auge_Ohr
what about INDEX ON STRZERO(field,9) ?
Re: Seek Option
Posted: Tue Mar 15, 2016 8:41 am
by Cliff Wiernik
We do this type of thing all the time: Not only leading zeros, but formatting. 4.254 becomes 400000254 and 2501 becomes 002501.000 or 250.1 becomes 000250.001,
This code is generic so it has more than you need, but it does the right adjusting when used in a get field or simply returning the expanded value for other purposes like the DC_AutoSeek()
Code: Select all
*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
*+ Function LB_RightAdj( InVar, InLen, FillChar, oGet, lReturnValue, lBlankOK )
*+
*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
FUNCTION LB_RightAdj( InVar, InLen, FillChar, oGet, lReturnValue, lBlankOK ) // PC CAW 12-31-14 added lBlankOK and additional coding
LOCAL objget
DEFAULT lReturnValue TO .F.
DEFAULT lBlankOK TO .F. // PC CAW 12-31-14
DEFAULT FillChar TO SPACE(1)
IF lBlankOK .AND. empty(inVar) // PC CAW 12-31-14
FillChar := SPACE(1)
ENDIF
InVar := RIGHT( REPLICATE( FillChar, InLen ) + TRIM( InVar ), InLen )
IF .NOT. lReturnValue
oGet:get:VarPut( InVar )
oGet:setData()
oGet:home()
ENDIF
IF lReturnValue
RETURN (InVar)
ENDIF
RETURN .T.
And the code from our seek field for a DCBROWSE:
Code: Select all
@ .2,1 DCSAY 'Enter Secured Party' GET cSeek ;
SAYRIGHTBOTTOM PICTURE '@!' ; // defines seek key for auto seek
GETOBJECT oV:d_oSeekkey ;
PARENT oV:d_oTabstatic1 ;
SAYSIZE 0 ;
EDITPROTECT {|| .F.} ;
LOSTFOCUS {|| cSeek := space(20), oV:d_oSeekkey:setdata() } ;
KEYBLOCK {|a,b,o| DC_BrowseAutoSeek(a,o,oV:d_oBrowse,,,'', ;
{|a| iif(empty(a),'',LB_RightAdj(a,4,'0',,.T.))})}
We use code like this in most of our browses. We never use a numeric index key, always character values and even our numeric appearing keys are actually alpha keys that look like numbers. We allow the entry of only significant digits most of the time, even if the insertions are in the middle.