A few minutes of your valuable time, for help please - Unos minutos de su valioso tiempo, para una ayuda por favor

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
Jose Marte2
Posts: 45
Joined: Thu Nov 16, 2017 2:19 pm
Location: República Dominicana

A few minutes of your valuable time, for help please - Unos minutos de su valioso tiempo, para una ayuda por favor

#1 Post by Jose Marte2 »

English

Greetings, everyone, I hope you are well as well as your families.

Sorry for the inconvenience and maybe the question is a bit silly.
I need a few minutes of your valuable time please.
Here I present a text file with some articles
and the query I want to make
I explain
I want to write for example LIJA 80
Please present me with all items that have those words in the description, no matter where it is.
The problem is that it only works for me with the word LIJA but if I add something else, in this case 80 or something else, it doesn't show anything.
Please do a quick check on the code or instruction that
What am I using, what am I doing wrong or is there any other more efficient way?
I'm still using DBF and NTX index

Thank you

Español

Saludos, para todos, espero que esten bien al igual que sus familias.
Disculpen las molestias y a lo mejor la pregunta si es algo tonta
Necesito por favor unos minutos de su valioso tiempo
Aqui le presento un archivo de texto con algunos articulos
y la consulta que deseo realizar
le explico
Quiero al escribir por ejemplo LIJA 80
Que me presente todos articulos que en la descripcion tenga esas palabras no importa donde este
El problema es que solo me funciona con la palabra LIJA pero si le agrego algo mas en este caso 80 u otra cosa no me presenta nad
Por favor una verificacion rapida al codigo o la instruccion que
estoy usando que estoy haciendo mal o si hay alguna otra forma mas eficiente
Estoy todavia usando DBF e indice NTX

Gracias


PROCEDURE ConsultaInventarioRapida( nFila1,nColu1,nFila2,nColu2,pDes )
LOCAL cConTit := " Consulta De Articulos "

cBusDes := pDes

nPrevArea := SELECT()
DBSELECTAR( "INVFILEH" )
nRec := RECNO()
LimpiaIndice()

// Aqui Hago el indice para presentar la consulta
// Here I make the index to present the query

inTemp := AllTrim(cCoUsua)+cNumTer+"x"+SubStr(StrTran(Time(),":",""),3,4)
Index On RepDes To &inTemp For AT(Trim("&cBusDes"),RepDes)>0

DbGoTop()
cPrevColor := SETCOLOR()
nPrevCursor:= SETCURSOR(SC_NONE)
SalvaPanta()
SalvaKey()
SETCOLOR(aColores[CO_MENUNOR])
ImprFnKey({{"Esc","Retornar"},{"PgUp-PgDn","P ginar"},{"Enter","Seleccionar"}}, 0, 1)

cLetrero := "CODIGO DESCRIPCION EXISTENCIA PRECIO[1]"

lRetVal := ConsInv(07, 01, 23, 78, cConTit, cLetrero, {|| CamInv() },;
"@!", NIL,.t.,.f.,, {|| AuxCam() },nPosFila)

lNoConsultaF := .f.
IF lRetVal
lNoConsultaF:= .t.
pCodArtRapida := RepCod
ENDIF

DBGOTO( nRec )
DBSELECTAR( nPrevArea )
LimpiaIndice()
SETCURSOR( nPrevCursor )
SETCOLOR (cPrevColor)
RestPanta()
RestKey()
RETURN

01388 LIJA FLEX REX N.80 SILOX
LIJA-01 LIJA ABRALI N.600
LIJ-01 LIJA AGUA NORTON N. 500
01286 LIJA AGUA # 100 ABRALI 324
00931 LIJA AGUA # 150 ABRALI/TRUPER
2019 LIJA AGUA # 1500 NORTON 1919
2016 LIJA AGUA # 180 GRINCO 1916
2020 LIJA AGUA # 2000 NORTON 1920
2009 LIJA AGUA # 220 NORTON/TRUPE
2011 LIJA AGUA # 280 GRINGO 1911
12345 LIJA AGUA # 280 NORTON 1424
00928 LIJA AGUA # 320 GRINCO 1281
2012 LIJA AGUA # 320 NORTON 1912
00929 LIJA AGUA # 360 NORTON 505
00930 LIJA AGUA # 400 ORIENTCRAFT
2013 LIJA AGUA # 400 TRUPER 1913
2014 LIJA AGUA # 600 GRINCO 1914
2018 LIJA AGUA # 80 NORTON 1918
2015 LIJA AGUA # 800 GRINCO 1915
LIJA LIJA AGUA # 800 KOLNY
LIJA001 LIJA AGUA # 800 NORTON
LIJA-036 LIJA AGUA #100 NORTON
LIJA-000 LIJA AGUA #120 OPTIMA
1712 LIJA AGUA #150 NORTON 1579
2017 LIJA AGUA 120 ABRACOL 1917
LIJA-0001 LIJA AGUA 180 TRUPER
01236 LIJA AGUA 220 OPTIMA
01235 LIJA AGUA 80 TRUPER 1336
02020 LIJA AGUA GRINCO N.2000
LI-01 LIJA AGUA N.1200 GRINCO MEDIA
LI-06 LIJA AGUA N.1200 LISA
0935 LIJA AGUA NORTON N.120
2010 LIJA DE AGUA # 240 ABRALI/NORTON
LI-03 LIJA DE AGUA N.1500 LISA
LI-07 LIJA DE AGUA N.2000 LISA
01712 LIJA DE TELA P/ESMERIL N.150
LIJ-001 LIJA FLEX REX 40 VERDE
LIJAAG LIJA NORTON 1200 (AGUA)
LIJA01 LIJA P/ FLEX REX 3M VERDE #40
00934 LIJA TELA # 100 NORTON
00932 LIJA TELA # 50 NORTON
01324 LIJA TELA # 60 NORTON
00933 LIJA TELA # 80 NORTON
00935 LIJA TELA #120 NORTON
LI LIJA TELA N.40
000927 LIJA TELA NORTON NUM
000935 LIJA TELA P/ESMERIL N.120 SHARPNESS
1579 LIMA # 6 MANGO ROJO TW BLISTER AZUL
00698 LIMA BELLOTA C/ MANGO GDE
00697 LIMA BELLOTA P/ CIERRA PEQ
00699 LIMA ESCORFINA P/M GRANDE
LIM-02 LIMA ITALO GRANDE C/M
00674 LIMA PLANA P/ANILLA # 8 TRUPER
00096 LLAVE ALLEN TRUPER 7/1 NORMAL
José Marte
Software & Servicios


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

Re: A few minutes of your valuable time, for help please - Unos minutos de su valioso tiempo, para una ayuda por favor

#2 Post by skiman »

Hi,

You can search in the NTX file on file level. This means it is working super fast.
Just make sure you have an NTX file with the description as key. Then use the following function which will return an array. This array can be used with dc_setscopearray(). You will see that the speed is amazing even with 10.000 and more records.

I use the asterick as separator for the search key. You can have 3 keys in one search. So in your case the key should be *LIJA*80. In this case the result will contain all the records where both keys are in the description.

Here it is:

Code: Select all

FUNCTION WildSrch(cNTXFile,cSrchArg,nMaxHits)  // ------------------------------
**********************************************************************
/*
parameters    :  cNTXFile  : drive:\path\filename.ext
                             (the NTX-File, to be scanned)
                 cSrchArg  : character-string with the search-argument

                 nMaxHits  : If the result-array is as long as <nMaxHits>
                             the function returns.
                             If nMaxHits = NIL, nMaxHits is set to 10000
                             (Array is full..)

returns       :  aResult   : an array with the record-numbers who
                             matched <cSrchArg>
*/

 // Search Result
LOCAL aResult   := {}                // array to hold the record-numbers

 // For Low-Level-Services
LOCAL nBlock    :=1024               // Size of each index-page
LOCAL cBuffer   :=space(nBlock)      // Buffer for FREAD
LOCAL nHandle   :=-1                 // file-handle
LOCAL nLen      :=0                  // length of index-file
LOCAL nPages    :=0                  // index-pages (excl. header)


 // Index-Header (offset from 0, substr from 1 -> always (+1) )
LOCAL nPtrItemSize   := 13     // h0C -> Pointer to ItemSize (keysize+8)
LOCAL nPtrKeySize    := 15     // h0E -> Pointer to KeySize
LOCAL nPtrMaxItem    := 19     // h12 -> Pointer to max. items on each page

 // LOCAL nLenItem       :=0       // length of each item
LOCAL nLenKey        :=0       // length of each key
 // LOCAL nItemMax       :=0       // max. items on each page

 // IndexPage   (offset from 0, substr form 1 -> always (+1) )
LOCAL nPtrItemPage   := 1      // h00 -> Pointer to Items on this page

LOCAL nItemCnt       := 0      // items on this page

LOCAL x:=0, y:=0               // FOR-loop indices
LOCAL nPtrItem       :=0       // pointer to current item
LOCAL nItemOffset    :=0       // offset of current item
LOCAL cKey           :=""      // key-value of current item
LOCAL nRecord        :=0       // recno of current item (inside the DBF-File)

 // Check nMaxHits and Set Break
LOCAL lBreak    := .f.         // Break-Condition
LOCAL cSrch1 := " " , cSrch2 := " " , cSrch3 := " "
LOCAL nPos2 := 0 , npos3 := 0
LOCAL aReturn := {}             // sorted array
Local lOpenFile := .T. , aSettings:={}

default cSubKey := "*" 

cSrchArg := strtran(alltrim(strip(cSrchArg)),"+","*")

cSrch1 := substr(cSrchArg,2)
nPos2 := at(cSubkey,cSrch1)
if nPos2 > 0
    cSrch2 := substr(cSrch1,nPos2+1)
    cSrch1 := substr(cSrch1,1,nPos2-1)
    nPos3 := at(cSubKey,cSrch2)
    if nPos3 > 0
        cSrch3 := substr(cSrch2,nPos3+1)
        cSrch2 := substr(cSrch2,1,nPos3-1)
    endif
endif

nMaxHits := 50000      // if(nMaxHits==NIL,1000,nMaxHits)

cNtxFile += ".ntx"

 // Let's do..

 // FileOpen

nHandle := fopen(cNTXFile, FO_READ + FO_SHARED)

IF FError() <> 0
         dc_alert("Error opening the file:"+cNtxFile+str(FError() ))
ENDIF

 // Calculate how many pages excl. header-page

nLen    := fseek(nHandle, 0, FS_END)
nPages  := int(nLen/nBlock) - 1
fseek(nHandle,0)

 // Read Header and get some information

fread(nHandle, @cBuffer, nBlock )

 // nLenItem := BIN2W( substr(cBuffer,nPtrItemSize,2) )
nLenKey  := BIN2W( substr(cBuffer,nPtrKeySize,2) )
 // nItemMax := BIN2W( substr(cBuffer,nPtrMaxItem,2) )

 //Now Read all Index-Pages and check for Search-Value

FOR X := 1 to nPages

    fread(nHandle, @cBuffer, nBlock)

     // check how many items on this page
    nItemCnt := BIN2W( substr(cBuffer, nPtrItemPage, 2) )

     // check all items on this page
    FOR Y := 1 TO nItemCnt

         // Page-Offset to read Item-Offset
        nPtrItem := (y*2)+1

         // Read Item-Offset
        nItemOffset := BIN2W( substr(cBuffer, nPtrItem, 2) ) + 1

         // Check current item
        cKey := substr(cBuffer, nItemOffset+8, nLenKey)
        if at(cSrch1, cKey) != 0 .and. at(cSrch2,cKey) != 0 .and. at(cSrch3,cKey) != 0
            // Read recno from index-page (beginning at <nItemOffset+4>)
           nRecord  := BIN2L( substr(cBuffer, nItemOffset+4, 4) )
            // Add recno to result-array
           aadd(aResult, {nRecord,cKey,cKey})

            // Check nMaxHits
           if len(aResult) >= nMaxHits
              lBreak := .t.
              EXIT
           endif

        endif

    NEXT Y

    if lBreak
       EXIT
    endif

NEXT X
 // close NTX-File
fclose(nHandle)
return aResult
I have the above code extracted from my sources. It is possible that there is specific function or variable left in the code. If so, just remove it.
Best regards,

Chris.
www.aboservice.be

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

Re: A few minutes of your valuable time, for help please - Unos minutos de su valioso tiempo, para una ayuda por favor

#3 Post by Auge_Ohr »

hi,

Xbase++ have OrdWildSeek() which might can help you with your Problem
greetings by OHR
Jimmy

Post Reply