Seek Option

This forum is for general support of Xbase++
Post Reply
Message
Author
omni
Posts: 547
Joined: Thu Jan 28, 2010 9:34 am

Seek Option

#1 Post 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

User avatar
rdonnay
Site Admin
Posts: 4775
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Seek Option

#2 Post 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.
The eXpress train is coming - and it has more cars.

skiman
Posts: 1195
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Seek Option

#3 Post 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.
Best regards,

Chris.
www.aboservice.be

User avatar
Auge_Ohr
Posts: 1422
Joined: Wed Feb 24, 2010 3:44 pm

Re: Seek Option

#4 Post by Auge_Ohr »

what about INDEX ON STRZERO(field,9) ?
greetings by OHR
Jimmy

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Seek Option

#5 Post 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.

Post Reply