Page 2 of 2

Re: DBSEEK - Problemas con la busqueda alfabetica

Posted: Mon Jan 27, 2020 4:59 am
by franco
this works
fieldname = Name (character ,30) value TOM SMITH
use customer
set index to custname
N := 'TOM SMITH'
N := N + SPACE(LEN(NAME)-LEN(N))
SEEK N
FOUND() = .T.
N := 'TOM SMIT'
N := N + SPACE(LEN(NAME)-LEN(N))
SEEK N
FOUND() = .F.

Re: DBSEEK - Problemas con la busqueda alfabetica

Posted: Mon Jan 27, 2020 9:51 am
by AUGE_OHR
franco wrote: Mon Jan 27, 2020 4:59 am this works
please use Code "Tag"
CodeTag.jpg
CodeTag.jpg (4.73 KiB) Viewed 1503 times
Ok i see you want your "own" SEEK like this

Code: Select all

#include "hmg.ch"
#include "Dbstruct.ch"
REQUEST HB_GT_WIN_DEFAULT           // Console

PROCEDURE MAIN
LOCAL aStru
   CLS
   IF !FILE("TEST.DBF")
      Cre_File("TEST.DBF")
   ENDIF
   USE TEST EXCLUSIVE
   aStru := DbStruct()
   nLen  := aStru[1][DBS_LEN]

   INDEX ON TEST->TESTC TO TESTC
   CLOSE INDEX

   SET INDEX TO TESTC
   SET ORDER TO 1       // TESTC

   PadSeek("TOM",nLen)
   ? found()
   PadSeek( "TOM S",nLen )
   ? found()
   PadSeek( "TOM SMITH",nLen )
   ? found()
   ? INDEXKEY()
   ? LEN(INDEXKEY())
   ? &(INDEXKEY())

WAIT
RETURN

FUNCTION PadSeek(cIn, nLen)
LOCAL cSeek
   cSeek := PADR(cIn,nLen," ")
   cSeek := SUBSTR(cSeek,1,nLen)
   SEEK cSeek
RETURN FOUND()

PROCEDURE Cre_File(cDBF)
LOCAL i, field_list := {}

   AADD( field_list, { "TESTC", "C", 10, 0 } )
   DBCREATE( cDBF, field_list, "DBFNTX" )

   USE (cDBF) EXCLUSIVE
   FOR i := 1 TO 100
      APPEND BLANK

      IF i = 50
         REPLACE TESTC WITH "TOM SMITH"
      ELSE
         REPLACE TESTC WITH Replicate( "TOM "+CHR( RANDOM(26)+64) , 6 )
      ENDIF
   NEXT

RETURN
DEMOSEEK.ZIP
(815 Bytes) Downloaded 143 times

Re: DBSEEK - Problemas con la busqueda alfabetica

Posted: Mon Jan 27, 2020 10:31 am
by Anand
From time of Clipper, I have been using below,

Code: Select all

use customer
set index to custname
N := 'TOM SMITH'
SEEK pad(N, LEN(NAME))
FOUND() => .T.
N := 'TOM SMIT'
SEEK pad(N, LEN(NAME))
FOUND() => .F.
And this works in Xbase++ and Harbour too.

Regards,

Anand

Re: DBSEEK - Problemas con la busqueda alfabetica

Posted: Mon Jan 27, 2020 4:51 pm
by franco
Thanks to all,
Anand, I forgot about pad