Search by line

Search by line

Postby Natter » Tue Feb 06, 2024 1:01 pm

Is there a search function for a line with a code block (a la ascan() ) ?
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Search by line

Postby Antonio Linares » Tue Feb 06, 2024 2:05 pm

Do you want to get each line or only a line that matches with a given one ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42118
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Search by line

Postby nageswaragunupudi » Tue Feb 06, 2024 2:06 pm

Search for a line in what?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Search by line

Postby karinha » Tue Feb 06, 2024 3:00 pm

Esto?

Code: Select all  Expand view  RUN

/*
 * Project: xFF - PESQTEXT.PRG \samples
 * File: xFF.prg
 * Description:
 * Author: JMSilva
 * Date: 06-25-2014
*/


#Include "FiveWin.ch"

FUNCTION Main()

   LOCAL oFont, oDlg, oMemo, oBtnSair, oIco, oBrush
   LOCAL oKey, cKey := Space( 20 ), oBtnFind, cText

   DEFINE BRUSH oBrush STYLE "BORLAND"
   DEFINE FONT oFont NAME "TAHOMA" SIZE 00, -14 BOLD

   DEFINE DIALOG oDlg TITLE "Pesquisa com GET TEXT" ;
      SIZE 680, 480 BRUSH oBrush FONT oFont         ;
      STYLE nOR( WS_SYSMENU, WS_MINIMIZEBOX )

   oDlg:lHelpIcon := .F.

   cText := MemoRead( "Teste.txt" ) // pode ser campo memo

   @ 4, 3 GET oMemo VAR cText MEMO OF oDlg PIXEL SIZE 330, 192 FONT oFont

   oMemo:bGotFocus := {|| oMemo:SetSel( 0, 0 ) }
   oMemo:lReadOnly := .T.  // nÆo edita

   @ 14, 1 SAY "PESQUISA:" COLOR CLR_HBLUE TRANSPARENT

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   @ 16, 5 GET oKey VAR cKey PICTURE "@!"                                    ;
      ACTION ( Find( oMemo, Trim( cKey ), .T. ), oBtnFind:Enable() )

   oKey:bKeyChar := {|| oBtnFind:Disable() }

   @ 204, 120 BTNBMP oBtnFind PROMPT "&Próximo" SIZE 40, 18 CENTER 2007      ;
      ACTION Find( oMemo, Trim( cKey ), .F. ) WHEN Find()

   oBtnFind:Disable()

   @ 204, 290 BTNBMP oBtnSair PROMPT "&Sair" SIZE 40, 18 CENTER 2007         ;
      ACTION( oDlg:End() )

   oBtnSair:lCancel := .T.

   ACTIVATE DIALOG oDlg CENTERED ON INIT( xFocus( oKey ) )

   IF Set( _SET_INSERT, ! Set( _SET_INSERT ) )
      Set( _SET_INSERT, ! Set( _SET_INSERT ) )
   ENDIF

   oBrush:End()
   oFont:End()

RETURN NIL

FUNCTION Find( oMemo, cFind, lNew )

   LOCAL nIndex  := 0

   STATIC nStart := 0

   IF PCount() == 0 ; RETURN( nStart > 0 ) ; ENDIF // when

   IF lNew ; nStart := 1; ENDIF                    // start

   nIndex := At( Trim( cFind ), Upper( oMemo:cText ), nStart, Len( oMemo:cText ) )

   IF nIndex > 0

      oMemo:Setfocus()     // seta o focu
      oMemo:SetPos( nIndex - 1, nIndex ) // posiciona
      oMemo:SetSel( nIndex - 1, nIndex + Len( Trim( cFind ) ) - 1 )

      RESetSelection( oMemo:hWnd, nIndex + Len( Trim( cFind ) ), nIndex )  // faz a rolagem do texto

      oMemo:Change()

      nSTART := nIndex + Len( Trim( cFind ) )// para continuar a pesquisa

   ELSEIF lNew

      MsgStop( "A palavra: " + cFind + " não foi localizada", "Find" )

      oMemo:SetSel( 0, 0 )

      nStart := 1

   ELSE

      MsgStop( "Nenhuma outra ocorrência foi encontrada", "Find" )

      nIndex := nStart - Len( Trim( cFind ) )

      oMemo:SetPos( nIndex - 1, nIndex ) // posiciona

   ENDIF

RETURN( .T. )
//-------------------------------------------------------------------------//
// As vezes simples SetFocus( oObj ) nao faz um objeto ganhar foco
// neste caso pode apelar para estas duas funcoes a seguir
// Forcar foco para um objeto especifico - Ednaldo Rolim...
//-------------------------------------------------------------------------//
FUNCTION xFocus( oObj )

   xSetFocus( oObj )
   xSetFocus( oObj )

RETURN( .T. )

FUNCTION xSetFocus( oObj )    

   LOCAL _oWnd := oObj:oWnd, _oTempo := ""

   DEFINE TIMER _oTempo INTERVAL 10 OF _oWnd ;
      ACTION ( oObj:SetFocus(), _oTempo:End() )

   ACTIVATE TIMER _oTempo

RETURN( .T. )

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Search by line

Postby Natter » Tue Feb 06, 2024 4:21 pm

I needed to find out if the string consists only of numbers or not. I wrote such a function:

if AtLine(adr, "{|xx|asc(xx)<48.or.asc(xx)>57}")=0
...............................................
endif

function AtLine(itm, xBk) 
local st, nOk:=0
** itm - string 
** xBk - code block 

xBk:=&xBk
for st=1 to len(itm)
if eval(xBk, itm[st])
nOk:=st
exit
endif
next
return nOk

It works fine, but I wanted to know if there is already a similar function
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Search by line

Postby Detlef » Tue Feb 06, 2024 4:53 pm

You could use regex function HB_RegEx().
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: Search by line

Postby karinha » Tue Feb 06, 2024 6:10 pm

Algo asi?

Code: Select all  Expand view  RUN

#include "FiveWin.ch"

FUNCTION Main()

   ? VerString( "001432 DAIANE 5555 OLIVEIRA UBA" )

RETURN NIL

FUNCTION VerString( cStr )

   LOCAL cStrNova := ""
   LOCAL nCt := 0, n1

   FOR n1 := 1 TO Len( AllTrim( cStr ) )

      IF .NOT. IsAlpha( SubStr( cStr, n1, 1 ) ) .AND. .NOT. ;
         Empty( SubStr( cStr, n1, 1 ) )

         nCt++

         IF nCt <= 3

            cStrNova += SubStr( cStr, n1, 1 ) // conta os primeiros 3 digitos.

            // ? cStrNova

         ENDIF

      ELSE

         cStrNova += SubStr( cStr, n1, 1 )  // conta somente as letras.

         // ? cStrNova

      ENDIF

   NEXT n1

// ? cStrNova

Return( cStrNova )

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7832
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Search by line

Postby Natter » Tue Feb 06, 2024 6:15 pm

Thanks, Detlef! Where can I see the description of the HB_RegEx() function ?
Natter
 
Posts: 1224
Joined: Mon May 14, 2007 9:49 am

Re: Search by line

Postby Detlef » Tue Feb 06, 2024 9:53 pm

If you give me your email adress I will send you the docs.
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 36 guests