Text File Processing

Harbour have many features for text file processing, manipulation.

Global Processing : taking text files as a single string.

MemoRead Return the text file’s contents as a character string
MemoWrit Write a memo field or character string to a text file on disk
HB_MemoRead Return the text file’s contents as a character string
HB_MemoWrit Write a memo field or character string to a text file on disk

A Class to read a text file

TFileRead Read a file one line at a time

In Harbour it’s possible also manipulate text files same as table ( .dbf ) files.

This group of function may be used for this purpose.

The basic structure is :

HB_FUse( <cTextFile> ) <-- open text file as a table

 WHILE .NOT. HB_FEof() <-- continue process for all lines in the file
c1Line := HB_FReadLN() <-- read a record (line) from file

 .... <-- process line 

 HB_FSkip() <-- advance record ( line ) pointer

 ENDDO

 HB_FUse() <-- close file

Special Text File Processing Functions

HB_FAtEOF() Chech EOF status of given work area
HB_FEof() Check end of text file status
HB_FGoBottom() Go to the last record in a text file
HB_FGoto() Move record pointer to specific record in the selected text file
HB_FGoTop() Move the record pointer to the first record in selected text file
HB_FInfo() Retrieves status information about the currently selected text file
HB_FLastRec() Get the number of records in the currently selected text file
HB_FReadAndSkip() Reads the current line and moves the record pointer to the next line
HB_FreadLN() Read a line from the selected text file without moving the record pointer
HB_FRecno() Return the current line / record number of a text file
HB_FSelect() Select a text file work area
HB_FSkip() Move the record pointer to a new position in a text file
HB_FUse() Open or close a text file for use by the HB_F* functions

A ‘global’ sample for HB_F* text  file processing functions : download.

TFP_Test_ScreenShoots

Harbour All Functions – H

HardCR

HBClass()

HB_ANSITOOEM()

hb_At

hb_cdpSelect

HB_ColorIndex

HB_DiskSpace

HB_EOL

HB_FEof

hb_FLock

hb_FUnlock

hb_gcAll
hb_gcAlloc
hb_gcCollectAll
hb_gcFree
hb_gcItemRef

hb_GetEnv

hb_HAllocate

hb_Hash
hb_HAutoAdd
hb_HBinary
hb_HCaseMatch
hb_HClone
hb_HCopy
hb_HDefault
hb_HDel
hb_HDelAt
hb_HEval
hb_HFill
hb_HGet
hb_HGetDef
hb_HHasKey
hb_HKeyAt
hb_HKeys
hb_HMerge
hb_HPairAt
hb_HPos
hb_HScan
hb_HSet

hb_HSetAutoAdd()
hb_HSetBinary() 
hb_HSetCaseMatch()

hb_HSort
hb_HValueAt
hb_HValues

hb_idleAdd
hb_idleDel
hb_idleState

hb_inetAddress
hb_inetCleanup
hb_inetClearError
hb_inetClearPeriodCallback
hb_inetClearTimeLimit
hb_inetClearTimeout
hb_inetClose
hb_inetConnect
hb_inetConnectIP
hb_inetCount
hb_inetCreate
hb_inetCRLF
hb_inetDataReady
hb_inetDGram
hb_inetDGramBind
hb_inetDGramRecv
hb_inetDGramSend
hb_inetErrorCode
hb_inetErrorDesc
hb_inetFD
hb_inetGetAlias
hb_inetGetHosts
hb_inetGetRcvBufSize
hb_inetGetSndBufSize
hb_inetInit
hb_inetIsSocket
hb_inetPeriodCallback
hb_inetPort
hb_inetRecv
hb_inetRecvAll
hb_inetRecvEndblock
hb_inetRecvLine
hb_inetSend
hb_inetSendAll
hb_inetServer
hb_inetSetRcvBufSize
hb_inetSetSndBufSize
hb_inetstatus
hb_inetTimeLimit
hb_inetTimeout

HB_IsByRef()

hb_keyPut

hb_langErrMsg
hb_langMessage
hb_langName
hb_langSelect

hb_mathErBlock
hb_mathErMode
hb_mathGetErrMode
hb_mathGetHandler
hb_mathGetLastError
hb_mathIsMathErr
hb_mathResetError
hb_mathSetErrMode
hb_mathSetHandler

hb_MemoRead
hb_MemoWrit

hb_RAt

hb_PIsByRef

hb_PValue

hb_SetKeyCheck
hb_SetKeyGet
hb_SetKeySave

hb_setListenerAdd

hb_setListenerNotify
hb_setListenerRemove

hb_SetMacro

hb_Translate

hb_ValToStr

Header

HexaToDec

MemoRead()

MEMOREAD()

Return the text file’s contents as a character string

Syntax

      MEMOREAD( <cFileName> ) --> cString

Arguments

<cFileName> is the filename to read from disk. It must include the file extension. If file to be read lives in another directory, you must include the path.

Returns

Returns the contents of a text file as a character string.

If <cFileName> cannot be found or read MEMOREAD returns an empty string (“”).

Description

MEMOREAD() is a function that reads the content of a text file (till now) from disk (floppy, HD, CD-ROM, etc.) into a memory string. In that way you can manipulate as any character string or assigned to a memo field to be saved in a database.

MEMOREAD() function is used together with MEMOEDIT() and MEMOWRIT() to get from disk text from several sources that would be edited, searched, replaced, displayed, etc.

It is used to import data from other sources to our database.

Note: MEMOREAD() does not use the settings SET DEFAULT or SET PATH to search for <cFileName>. It searches for <cFileName> in the current directory. If the file is not found, then MEMOREAD() searches in the DOS path.

Over a network, MEMOREAD() attempts to open <cFileName> in read-only mode and shared. If the file is used in mode exclusive by another process, the function will returns a null string (“”).

Examples

      *  This example uses MEMOREAD() to assign the contents of a text
      *  file to a character variable for later search

         cFile   := "account.prg"
         cString := MEMOREAD( cFile )
         cCopyright := "Melina"

         IF At( "Melina", cString ) == 0            // check for copyright
            MEMOWRIT( cFile, cCopyright + cString ) // if not, add it!
         ENDIF

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

MEMOEDIT(), MEMOWRIT(), REPLACE, HB_MEMOREAD()

hb_MemoRead()

HB_MEMOREAD()

Return the text file’s contents as a character string

Syntax

      HB_MEMOREAD( <cFileName> ) --> cString

Arguments

<cFileName> is the filename to read from disk. It must include the file extension. If file to be read lives in another directory, you must include the path.

Returns

Returns the contents of a text file as a character string.

If <cFileName> cannot be found or read HB_MEMOREAD returns an empty string (“”).

Description

HB_MEMOREAD() is a function that reads the content of a text file (till now) from disk (floppy, HD, CD-ROM, etc.) into a memory string. In that way you can manipulate as any character string or assigned to a memo field to be saved in a database.

HB_MEMOREAD() function is used together with MEMOEDIT() and HB_MEMOWRIT() to get from disk text from several sources that would be edited, searched, replaced, displayed, etc.

It is used to import data from other sources to our database.

Note: HB_MEMOREAD() does not use the settings SET DEFAULT or SET PATH to search for <cFileName>. It searches for <cFileName> in the current directory. If the file is not found, then HB_MEMOREAD() searches in the DOS path.

Over a network, HB_MEMOREAD() attempts to open <cFileName> in read-only mode and shared. If the file is used in mode exclusive by another process, the function will returns a null string (“”).

HB_MEMOREAD() vs MEMOREAD(): HB_MEMOREAD() is identical to MEMOREAD() except it won’t truncate the last byte (on non-UNIX compatible systems) if it’s a EOF char.

Examples

      *  This example uses HB_MEMOREAD() to assign the contents of a text
      *  file to a character variable for later search

         cFile   := "account.prg"
         cString := HB_MEMOREAD( cFile )
         cCopyright := "Melina"

         IF At( "Melina", cString ) == 0               // check for copyright
            HB_MEMOWRIT( cFile, cCopyright + cString ) // if not, add it!
         ENDIF

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

MEMOEDIT(), HB_MEMOWRIT(), REPLACE, MEMOREAD()