How to SCAN substrings in a dbf - Summer 87

Fórum sobre a linguagem CA-Clipper.

Moderador: Moderadores

alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

How to SCAN substrings in a dbf - Summer 87

Mensagem por alxsts »

Hi!

Here goes the entire source code (not compiled and not tested). Hope it helps you.

Código: Selecionar todos

PROCEDURE REC_FND

PRIVATE REC2FIND, SAV_REC
PRIVATE cOldArea, cOldScreen
PRIVATE cBorder = CHR(218) + CHR(196) + CHR(191) + CHR(179) +;
         CHR(217) + CHR(196) + CHR(192) + CHR(179)

* Save current position in database if search fails
*--------------------------------------------------
SAV_REC = recno()

set color to &GET_CLR
read


* Continue if escape wasn't pressed
*----------------------------------
IF LASTKEY()#ESC_KEY
*--------------------------------

   REC2FIND = space(40)

   do DISP_MSG with 'Client (include punctuation): '

   @row(),col() get REC2FIND

   read

   * Continue if the escape key was not pressed
   *-------------------------------------------
   IF lastkey() # ESC_KEY

      * Remove trailing spaces
      *-----------------------
      REC2FIND = UPPER(trim(REC2FIND))

      *-- AlxSts - Start ---------------------*

      * Save current work area
      cOldArea = Select()
      
      * iF tmpTable exists, delete it
      IF File("tmpTable.dbf")
         ERASE tmpTable.dbf
         ERASE tmpTable.ntx
      ENDIF

      * Create tmpTable...      
      COPY STRUCTURE FIELDS COMPNY_NAM, CASE_LNAME TO tmpTable

      USE tmpTable EXCLUSIVE
         
      * tmpTable is now the current selected work area... loop the entire main table...
      DO WHILE cases->( ! Eof() )
         cString = ""
         * search LNAME first because if REC2FIND exists in both fields, LNAME takes precedence
         IF (REC2FIND $ UPPER(cases->CASE_LNAME))
            * Person's last and first names
            cString = Trim( cases->CASE_LNAME ) + ", " + cases->CASE_FNAME   && assuming there is a field named CASE_FNAME (first name) 
         ELSEIF (REC2FIND $ UPPER(cases->COMPNY_NAM))
            * Company name 
            cString = cases->COMPNY_NAM
         ENDIF

         IF Len( cString) > 0
            * something was found. Save it...   
            APPEND BLANK
            IF .Not. NetErr()
               tmpTable->COMPNY_NAM = cases->COMPNY_NAM
               tmpTable->CASE_LNAME = Upper( cString )
            ELSE
               * Error. Display some message and Exit
               do DISP_MSG with [Error writing temporary file. Press a key to exit.]            
               SELECT Cases
               go SAV_REC
               RETURN
            ENDIF 
         ENDIF
         cases->( DbSkip() )
      ENDDO

      * If anything was found...
      IF tmpTable->( LastRec() ) > 0

         * tmpTable is still the current selected work area. Create an index
         INDEX ON CASE_LNAME TO tmpTable

         GO TOP
         
         * Save the screen area used by popup window
         *---------------------
         cOldScreen = SAVESCREEN(5, 14, 20, 63)

         * Draw a box with single border
         *---------------------
         @ 5, 14, 20, 63 BOX cBorder

         * Browse records in tmp table until user
         * cancels browsing (ESC) or a record is selected (ENTER)
         *---------------------

         DBEDIT(6, 15, 19, 62, {"tmpTable->CASE_LNAME"} , "_REC_FND_", NIL, {" Select a name "})

         * Restore screen region
         *---------------------
         RESTSCREEN(5, 14, 20, 63, cOldScreen)

         * Restore previous work area
         *---------------------
         
         Select( cOldArea )

         IF LASTKEY() # ESC_KEY
            * User selected someone.
            * Save company name from tmp table...
            *---------------------
            REC2FIND = TRIM(tmpTable->COMPNY_NAM)

            * Seek for selected company name
            * in the original table...
            *---------------------
            * Get client index
            *--------------------
            set order to 7

            * Search using the key
            *---------------------
            set exact off
         
            seek REC2FIND
            set exact on

            * Return to the first index
            *--------------------------

            set order to 1

            * If found, put the highlight bar on the record
            *----------------------------------------------
            if !eof()

               do SCRL_TOS

            else

               * If not found, tell the user
               *----------------------------

               do DISP_MSG with [Client, ]+trim(REC2FIND)+[, not found. Press a key.]

               inkey(0)

               go SAV_REC

            endif
         ELSE
           * user cancelled...
           go SAV_REC
         ENDIF
      ELSE
         * no matches found...
         Select( cOldArea )
         do DISP_MSG with [Client, ]+trim(REC2FIND)+[, not found. Press a key.]
         inkey(0)
         go SAV_REC
      ENDIF

      * delete tmpTable...
      SELECT( "tmpTable" )
      USE

      ERASE tmpTable.dbf
      ERASE tmpTable.ntx

      SELECT( cOldArea )

   ENDIF

   *-- AlxSts - End ---------------------*

ENDIF

RETURN

*----------------------------
* User function for DbEdit()
*----------------------------

FUNCTION _REC_FND_

PARAMETERS status, fld_ptr

PRIVATE request

*
key_stroke = LASTKEY()
*

   *Table: Requests to DBEDIT() from User Function
   *----------------------------------------------------------
   *Value   Description
   *----------------------------------------------------------

   * 0    Quit DBEDIT()
   * 1    Continue DBEDIT()
   * 2    Force reread/repaint and continue;
   *      after repaint, process keys, and go to idle
   * 3    Append mode (not recommended)
   *----------------------------------------------------------

DO CASE
   CASE status = 0
      * Idle. Continue
      request = 1
   CASE status = 1
      * Beginning-of-file.
      request = 1
   CASE status = 2
      * End-of-file.
      request = 1
   CASE status = 3
      * Empty database file.
      request = 0
   CASE status = 4
      * Key exception.
      IF key_stroke = 27
       * Exit
       request = 0
      ELSEIF key_stroke = 13
       * Record selected...
       * exit with temp table file pointer over selected record
       request = 0
      ENDIF
   OTHERWISE
      request = 1
ENDCASE

*
RETURN request*
[]´s
Alexandre Santos (AlxSts)
esgici
Usuário Nível 1
Usuário Nível 1
Mensagens: 34
Registrado em: 27 Ago 2012 14:51
Localização: Turkiye
Contato:

How to SCAN substrings in a dbf - Summer 87

Mensagem por esgici »

Hi Alex

Código: Selecionar todos

      COPY STRUCTURE FIELDS COMPNY_NAM, CASE_LNAME TO tmpTable

      USE tmpTable EXCLUSIVE
Here the table tmpTable is empty !

You can see by adding

Código: Selecionar todos

    ? LASTREC() 
just after USE ... command.

It will write : 0 (zero)

Solution : Discard STRUCTURE keyword from COPY command.


Saludos
Saudação
Esgici
Viva Clipper !
alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

How to SCAN substrings in a dbf - Summer 87

Mensagem por alxsts »

Hi Esgici!

The tmpTable is intentionaly empty. I've created it with two fields from the original table. After, I traverse the main table (cases) appending the records meeting the criteria to the tempTable.
[]´s
Alexandre Santos (AlxSts)
Avatar do usuário
Pablo César
Usuário Nível 7
Usuário Nível 7
Mensagens: 5312
Registrado em: 31 Mai 2006 10:22
Localização: Curitiba - Paraná

How to SCAN substrings in a dbf - Summer 87

Mensagem por Pablo César »

Intentional and necessary to make a search in temporary file. But remember, opening in EXCLUSIVE mode at Network it could become an error opening crash if two users try same option for searching. My tip is to create a temporary file name with alleatory name (for example: "Tmp"+cSeconds or Tmp+UserName) or just to create this temporary in local machine (at C drive). In this last case, you will need just to add "C:"+name_of_temporary.dbf.
Um clip-abraço !

Pablo César Arrascaeta
Compartilhe suas dúvidas e soluções com todos os colegas aqui do fórum.
Evite enviar as dúvidas técnicas por MPs ou eMails, assim todos iremos beneficiar-nos.
esgici
Usuário Nível 1
Usuário Nível 1
Mensagens: 34
Registrado em: 27 Ago 2012 14:51
Localização: Turkiye
Contato:

How to SCAN substrings in a dbf - Summer 87

Mensagem por esgici »

AlxSts escreveu:The tmpTable is intentionaly empty. I've created it with two fields from the original table. After, I traverse the main table (cases) appending the records meeting the criteria to the tempTable.
Hi Alex

Sorry, I missed cases-> notation in the search statements

Hi Pablo,

how are you ?

I hope you stocked enough energy from holiday ;)

Why you don't invite Alex to Harbour ( by leaving S87 in the deep silenced sleep) :*

For example :

Código: Selecionar todos

FT_TEMPFIL() : Create a file with a unique name

Hb_FTempCreate()
hb_FTempCreateEx()
Moreover

Código: Selecionar todos

DBCREATE( "mem:test", ...   ( Memory file system )
Happy Clippering :D

Salute from Turkiye :xau
Saudação
Esgici
Viva Clipper !
Avatar do usuário
Pablo César
Usuário Nível 7
Usuário Nível 7
Mensagens: 5312
Registrado em: 31 Mai 2006 10:22
Localização: Curitiba - Paraná

How to SCAN substrings in a dbf - Summer 87

Mensagem por Pablo César »

esgici escreveu:Hi Pablo,

how are you ?

I hope you stocked enough energy from holiday ;)
Pretty well my friend. Yes I am full charge in my battery... :D
Why you don't invite Alex to Harbour ( by leaving S87 in the deep silenced sleep)
Ohh I know my amigo. But this post is from Merge who is from EUA and she is not founding substituting libraries for Harbour migration. That is the main reason for Clipper´s Summer version here in discuss and is not Alexandre fault.

But whos knows ? Probably Marge will takes in mind for next big step in your upgrades.

Thank you amigo Esgici for your usual and very kind of participation !
Um clip-abraço !

Pablo César Arrascaeta
Compartilhe suas dúvidas e soluções com todos os colegas aqui do fórum.
Evite enviar as dúvidas técnicas por MPs ou eMails, assim todos iremos beneficiar-nos.
esgici
Usuário Nível 1
Usuário Nível 1
Mensagens: 34
Registrado em: 27 Ago 2012 14:51
Localização: Turkiye
Contato:

How to SCAN substrings in a dbf - Summer 87

Mensagem por esgici »

Oh, yes;

I'm confused who was ask question and who was answered :(

But I'am wondered; what libraries required to substituting;

or what modules, functions / procedures may be used in a S87 project ?

If we know what are required, hopefully we may have some suggestions :)Pos

In our country we have an aphorism : An amigo is a mirror of amigo

My kindness is came from you :{

Happy Clippering :D
Saudação
Esgici
Viva Clipper !
Avatar do usuário
JoséQuintas
Administrador
Administrador
Mensagens: 20267
Registrado em: 26 Fev 2007 11:59
Localização: São Paulo-SP

How to SCAN substrings in a dbf - Summer 87

Mensagem por JoséQuintas »

I use more than one word for user to get more options.

anything like this:

Código: Selecionar todos

cText1 = Space(50)
cText2 = Space(50)
@ 12, 20 GET cText1 PICTURE "@!"
@ 13, 20 GET cText2 PICTURE "@!"
READ
cText1 = Trim(cText1)
cText2 = Trim(cText2)
SET FILTER TO cText1 $ Upper(dbf->nome) .AND. cText2 $ Upper(dbf->nome)
You could make only one get, split into an array and use array in filter.
José M. C. Quintas
Harbour 3.2, mingw, gtwvg mt, fivewin 25.04, multithread, dbfcdx, MySQL, ADOClass, PDFClass, SefazClass, (hwgui mt), (hmg3), (hmg extended), (oohg), PNotepad, ASP, stored procedure, stored function, Linux (Flagship/harbour 3.2)
"The world is full of kings and queens, who blind our eyes and steal our dreams Its Heaven and Hell"

https://github.com/JoseQuintas/
marge0512
Usuário Nível 3
Usuário Nível 3
Mensagens: 121
Registrado em: 20 Mai 2011 12:42
Localização: United States

How to SCAN substrings in a dbf - Summer 87

Mensagem por marge0512 »

Hello eveyone! And thank you for all of this information! I will make my next project trying to convert to Harbour. The last time i had tried doing that, it was not fun and i couldn't get the application to work right. But......I can debug in Harbour. Lol! Right now, I am trying to make my user happy. He hates having to search through thousands of records and wants to keep each and every one even though they are so old. So.....Summer87 for now.

I am using the code but had a hard time compiling because of a couple of mistakes I had made but that is working fine though now. Right now, I get the error that the CASES table does not exist when i get to this line:

*tmpTable is now the current selected wrok area…loop the
*entire main table
*---------------------------------------------------

DO WHILE Cases->(!EOF()) <-----------------Line of error.
cString = ""

Should I say USE Cases EXCLUSIVE? Something like that? I was having problems with this last week when i was trying to do the code by myself. This gets confusing for me. When i tried changing the code, I would get the error that the tmpTable did not exist.
esgici
Usuário Nível 1
Usuário Nível 1
Mensagens: 34
Registrado em: 27 Ago 2012 14:51
Localização: Turkiye
Contato:

How to SCAN substrings in a dbf - Summer 87

Mensagem por esgici »

Hi Marge

After

Código: Selecionar todos

      COPY STRUCTURE FIELDS COMPNY_NAM, CASE_LNAME TO tmpTable
and before

Código: Selecionar todos

      USE tmpTable EXCLUSIVE
add

Código: Selecionar todos

    SELECT 2
But caution: this 2 is correct if your open (USE'ed) table ( .dbf ) is only one at this point. If it is more than one you need change this 2 to "open tables count + 1"

I hope this will help you.

Salute
Saudação
Esgici
Viva Clipper !
marge0512
Usuário Nível 3
Usuário Nível 3
Mensagens: 121
Registrado em: 20 Mai 2011 12:42
Localização: United States

How to SCAN substrings in a dbf - Summer 87

Mensagem por marge0512 »

Thank you!

When i use SELECT 2, it works fine but i cannot compile when I use "open tables count + 1". I will check the syntax. I may be missing something.
esgici
Usuário Nível 1
Usuário Nível 1
Mensagens: 34
Registrado em: 27 Ago 2012 14:51
Localização: Turkiye
Contato:

How to SCAN substrings in a dbf - Summer 87

Mensagem por esgici »

Marge escreveu:... i cannot compile when I use "open tables count + 1". I will check the syntax. I may be missing something.
Oh, sorry;

"open tables count + 1" isn't a statement, only an arithmetic :(

I want to say : if your open table count is 1, then use here 2, if 2, use 3 ... and so on

Sorry for bad English :(

Regards
Saudação
Esgici
Viva Clipper !
alxsts
Colaborador
Colaborador
Mensagens: 3092
Registrado em: 12 Ago 2008 15:50
Localização: São Paulo-SP-Brasil

How to SCAN substrings in a dbf - Summer 87

Mensagem por alxsts »

Hi!

This is especially dificult because we can't see the whole source code.

When I started to read the cases table [WHILE cases->( !EOF())] I assumed it was open and was the currently selected work area when the REC_FND procedure was invoked. Assumed also that after selecting one record in the tmpTable the cases table is the one being SEEKed after in the code (in the order # 7). If this is not true, you must check the procedure that calls REC_FND procedure.

But it seems strange because it was working in both the version using COPY TO and SORT TO. In these previous versions I'm quite sure cases was the selected table when the procedure was called. Are you sure you haven't made some mistake?

If you follow Esgici sugestion (SELECT 2 ) may lead to unpredictable results...
[]´s
Alexandre Santos (AlxSts)
marge0512
Usuário Nível 3
Usuário Nível 3
Mensagens: 121
Registrado em: 20 Mai 2011 12:42
Localização: United States

How to SCAN substrings in a dbf - Summer 87

Mensagem por marge0512 »

I will double check. I definitely could be making a mistake. I could try sending you more of the code but there is a bit. I don't understand why that's happening because it seems that the CASES table gets opened in the beginning.
Avatar do usuário
Pablo César
Usuário Nível 7
Usuário Nível 7
Mensagens: 5312
Registrado em: 31 Mai 2006 10:22
Localização: Curitiba - Paraná

How to SCAN substrings in a dbf - Summer 87

Mensagem por Pablo César »

marge0512 escreveu:DO WHILE Cases->(!EOF()) <-----------------Line of error.
Try this in place:

do while .not. Cases->( eof() )

I think "!" beguns after 5.0
Um clip-abraço !

Pablo César Arrascaeta
Compartilhe suas dúvidas e soluções com todos os colegas aqui do fórum.
Evite enviar as dúvidas técnicas por MPs ou eMails, assim todos iremos beneficiar-nos.
Responder