FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Contar un caracter en archivo de texto
Posts: 1710
Joined: Tue Oct 28, 2008 06:26 PM
Re: Contar un caracter en archivo de texto
Posted: Thu Sep 12, 2013 08:13 PM
Mr. Rao
Perfect
I modified to display another column when the text is wide
It works, is it right?
This is code
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"
#include "fileio.ch"
#include "hbcompat.ch"

REQUEST DBFCDX

static hFile

//----------------------------------------------------------------------------//

function Main()

   local oWnd, oBrw
   local cTextFile   := "c:\TMP\REPORT\LIST21.LST"
   local cIndexDbf
   local c, k,lFont:= .t.

   cIndexDbf      := cFileSetExt( cTextFile, "dbf" )
   if ! File( cIndexDbf )
      MsgRun( "Creating Index", "PLEASE WAIT", { || CreateIndexDbf( cTextFile, cIndexDbf ) } )
   endif

   hFile    := FOpen( cTextFile )
   DEFINE FONT oBig  NAME "Courier New" SIZE  0,-13; DEFINE FONT oFont NAME "Courier New" SIZE 0,-11
   DEFINE FONT oFont1 NAME "Arial" SIZE 4, -8.4
   USE ( cIndexDbf ) NEW ALIAS TDX SHARED READONLY VIA "DBFCDX"
    nRecLen:=FIELD->RECLEN
   DEFINE WINDOW oWnd
   @ 0,0 XBROWSE oBrw OF oWnd DATASOURCE "TDX" ;
      FIELDS RecNo(), ReadLine(1),If(nRecLen>160,ReadLine(2),"" ); //Add
      HEADERS "No", "Text" ;
      PICTURES "9,999,999" ;
      NOBORDER

   WITH OBJECT oBrw
      :nStretchCol   := 2
      :lVThumbTrack  := .t.
       :nMarqueeStyle   := MARQSTYLE_HIGHLWIN7
      :nFreeze:=1
        :nColSel:=2
      :CreateFromCode()
   END
       oBrw:aCols[1]:nWidth:=35
         oBrw:aCols[1]:oDataFont:=oFont1
         oBrw:aCols[1]:nDataStrAlign:=AL_RIGHT
       
       oBrw:aCols[2]:oDataFont:= { || iif( lFont,oFont,oBig) }
       If nRecLen>160
           oBrw:aCols[3]:oDataFont:= { || iif( lFont,oFont,oBig) }
          Endif

   oWnd:oClient   := oBrw
   ACTIVATE WINDOW oWnd MAXIMIZED
   CLOSE TDX
   FClose( hFile )

return 0

//----------------------------------------------------------------------------//

static function ReadLine(nC)

   local nRead, cLine

   if FIELD->RECLEN == 0
      return ""
   endif

   FSeek( hFile, FIELD->OFFSET, FS_SET )
   cLine    := Space( FIELD->RECLEN )
   nRead    := FRead( hFile, @cLine, FIELD->RECLEN )
   If nC=2
       cLine:=Subs(cLine,47,200) //add
   Endif

return Left( cLine, nRead )

//----------------------------------------------------------------------------//

static function CreateIndexDbf( cFile, cDbf )

   local hFile
   local nBufSize := 32000
   local cBuf     := Space( nBufSize )
   local nRead, nPrevRead  := 0
   local nAt, nLen

   DbCreate( cDbf, {{ "OFFSET", 'N', 12, 0 }, { "RECLEN", 'N', 4, 0 }}, "DBFCDX", .t., "TDX" )
   DbAppend()
   FIELD->OFFSET  := 0

   hFile    := FOpen( cFile )
   do while .t.
      nRead    := FRead( hFile, @cBuf, nBufSize )
      nAt      := 1
      do while ( nAt := At( CRLF, cBuf, nAt, nRead ) ) > 0
         nLen  := nAt + nPrevRead - FIELD->OFFSET - 1
         FIELD->RECLEN  := nLen
         DBAPPEND()
         nAt++
         FIELD->OFFSET  := nAt + nPrevRead
         nAt++
      enddo
      if nRead < nBufSize
         exit
      else
         nPrevRead   += nBufSize
      endif
   enddo
   FIELD->RECLEN  := nRead + nPrevRead - FIELD->OFFSET
   CLOSE TDX

return nil

Now, how to do this, to show which page is
Code (fw): Select all Collapse
Static FUNCTION VerPag()
      nPagIni=1
    
      For vI:=1 To oBrw:nArrayAt
         IF At(chr(12),aTexto[ vI ][2])>0
             nPagIni++
         Endi
      Next vI     
      If(nPagIni>nPagTot,nPagIni--, )
      oSay:Refresh()
Return Nil


Find String
Code (fw): Select all Collapse
Static Funct BuscaCad(vQue)
       oBrw:Skip()
         For vI:= oBrw:nArrayAt To nRec
          IF At(AllTrim(vQue),UPPER(aTexto[ oBrw:nArrayAt ][2]))>0
             Exit          
          Endif
          oBrw:Skip()
          
          If vI=oBrw:nArrayAt
             oBrw:GoTop()
             MsgInfo("No existe cadena indicada")
             Exit      
              Endif
        Next vI
       (oBrw:Refresh(),oBrw:SetFocus())
Retu Nil


Thanks,

Regards

Adhemar
Saludos,



Adhemar C.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Contar un caracter en archivo de texto
Posted: Fri Sep 13, 2013 03:29 AM
  1. Are you trying to add extra column to show text that is overflowing the second column? It is better to provide horizontal scroll of cell contents than showing another column,
    Even then, your logic is defective.
  2. Page and line numbers should be generated and recorded in the index dbf
  3. You can not use nArrayAt because we are not browsing array.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion