Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse a text file 2

Status
Not open for further replies.

fbizzell

Programmer
Jul 3, 2000
217
0
0
Is there a clipper function for browsing a text file? All I want to do is display it on the screen and move up and down the display. I do not want to edit the text, only display it.

 
check out dbedit() .. you can pass parameters to the function to make it readonly!

Also, you can checkout tbrowse()

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
Dbedit() and Tbrowse work only with data files as far as I know.
 
Yup. MEMOEDIT().

It works for text files even.

It takes upto 13 parameters like:
- Source (memo filed name or text/char stirng,
- Screen co-ords (4 paramaters),
- Updatable flag
- User defined functions ..
and so on

For more, refer to your on-line NG help or the manual.

End
 
I think we are getting a little closer with Memoedit(). I have used that to display contents of memo fields in databases, but have not use it to display a text file. I will read up on it but I was hoping that someone had a short snippet of code that would open and display a dos text file, similar to the way notepad would display it.
 
Hi,

Here's some code

Use the Mody_Memo function like this:
Code:
Mody_Memo(MemoRead("C:\TextFile.txt"))
the underlying stuff is as follows:
Code:
FUNCTION MODY_MEMO
  ** this is a read / write memo edit function
  PARAMETER MSTRING
  PRIVATE MSTRING,Tp,Lt,Bt,Rt,WRAP,MACTFLG,OLDLINE
  PRIVATE MINSERT
  WRAP = 1
  Tp = 6
  Lt = 2
  Bt = 20
  Rt = 76
  DROP_BOX(Tp,Lt,Bt,Rt,17)
  D_MSG(" Enter revised note, @F4 to save, @Esc to abort")
  SET CURSOR ON
  MSTRING = STRTRAN(MEMOEDIT(MSTRING,Tp+1,Lt+1,Bt-1,Rt-1,.T.,"MEMOFUNC",(Rt-Lt)-1),CHR(26),"")
  SET CURSOR OFF
  RETURN(MSTRING)
MemoFunc is called as a key handler by MemoEdit (you can see it passed the reference above)
Code:
FUNCTION MEMOFUNC
  PARAMETERS MSTATUS,MROW,MCOL
  PRIVATE MSTATUS,MROW,MCOL,RETVAL
  RETVAL = 0
  IF MSTATUS = 3
    IF WRAP = 0
      WRAP = 1
      RETVAL = 34
    ENDIF
  ELSE
    IF MSTATUS = 0
      @ Bt,Lt+1 SAY "Row:"+STR(MROW,3)+" Col:"+STR(MCOL,3)
    ENDIF
    IF LASTKEY() = F4
      RETVAL = 23 && CTRL-W
    ENDIF
  ENDIF
  RETURN(RETVAL)
D_Msg is a very very old function that I wrote to display things on the bottom line of the display:
Code:
FUNCTION D_MSG
  PARAMETER MSG,MLINE,MLGTH
  PRIVATE MSG,MLINE,MLGTH
  PRIVATE OLDCOLOR,X,STRING,Y,VAL_STRING,Z
  DECLARE HI_LITE[20],HI_POS[20]
  IF PCOUNT() < 3
    MLGTH = 78
  ENDIF
  IF PCOUNT() < 2
    MLINE = 23
  ENDIF
  VOID=AFILL(HI_LITE,&quot;&quot;)
  VOID=AFILL(HI_POS,-1)
  OLDCOLOR=SETCOLOR(COLORS[10])
  RESTSCREEN(MLINE+1,2,MLINE+1,MLGTH,BGC(SAVESCREEN(MLINE+1,2,MLINE+1,MLGTH),8))
  STRING     =&quot;&quot;
  VAL_STRING =&quot;&quot;
  Y=0
  IF LEFT(MSG,1) <> &quot; &quot;
    MSG = &quot; &quot;+MSG
  ENDIF
  IF &quot;$&quot;$MSG .OR. &quot;@&quot;$MSG
    ** Scan string looking for Highlighters...
    FOR X =1 TO LEN(MSG)
      DO CASE
          ** Highlight next char only...
        CASE SUBSTR(MSG,X+Y,1) =&quot;$&quot;
          Y=Y+1
          HI_LITE[Y] =SUBSTR(MSG,X+Y,1)
          HI_POS[Y]  =X
          ** Highlight next word only...
        CASE SUBSTR(MSG,X+Y,1) =&quot;@&quot;
          Y=Y+1
          FOR Z =0 TO 10
            IF !(SUBSTR(MSG,X+Y+Z,1)$&quot; -,.>])&quot;)
              HI_LITE[Y] =HI_LITE[Y]+SUBSTR(MSG,X+Y+Z,1)
            ELSE
              Z =10
            ENDIF
          NEXT
          HI_POS[Y] =X
      ENDCASE
      STRING =STRING+SUBSTR(MSG,X+Y,1)
    NEXT
  ELSE
    STRING=MSG
  ENDIF
  ** Display the string...
  @ MLINE,1 SAY LEFT(STRING+SPACE(MLGTH-1),MLGTH-1)
  VOID=SETCOLOR(COLORS[11])
  ** Just do the highlights...
  FOR X =1 TO Y
    IF HI_POS[X] <> -1
      @ MLINE,HI_POS[X] SAY HI_LITE[X]
      ** Not using the VAL_string...
      ** VAL_STRING=VAL_STRING+HI_LITE[X]
    ELSE
      X =Y+1
    ENDIF
  NEXT
  VOID=SETCOLOR(OLDCOLOR)
  RETURN(STRING)
I use a C routing for the BGC (backgroundcolour) function
that D_Msg calls to shade the boxes - but here is a Clipper variant:
Code:
FUNCTION BGC
  PARAMETERS STRING,X
  ** pass the function the 'save screen' string and the ascii value to be used
  PRIVATE X,I,NEWSTRING
  ** invent a new string...
  NEWSTRING=&quot;&quot;
  FOR I = 1 TO LEN(STRING) STEP 2
    ** take each alternate char and add to new string...
    NEWSTRING = NEWSTRING+SUBSTR(STRING,I,1)+CHR(X)
  NEXT
  ** return the new string to the caller...
  RETURN(NEWSTRING)
Lastly, here is a 'drop_box' function to make things pretty:
Code:
FUNCTION DROP_BOX
  PARAMETERS T,L,B,R
  PRIVATE T,L,B,R,X,I
  *FOR X = T TO B
  RESTSCREEN(T+1,L+1,B+1,R+1,BGC(SAVESCREEN(T+1,L+1,B+1,R+1),8))
  *NEXT
  FOR X = T TO B
    @ X,L CLEAR TO X,R
    FOR I = 1 TO 20 && Short delay loop...
    NEXT I
  NEXT
  @ T,L TO B,R
  RETURN(.T.)

Put it all together and you have an edit memo function:

HTH


Regards

Griff
Keep [Smile]ing
 
I'll give you another technique later - gotta go.



Regards

Griff
Keep [Smile]ing
 
If you want to force a readonly state change the sixth parameter in the Memoedit call to be false:

Code:
MSTRING = STRTRAN(MEMOEDIT(MSTRING,Tp+1,Lt+1,Bt-1,Rt-1,.F.,&quot;MEMOFUNC&quot;,(Rt-Lt)-1),CHR(26),&quot;&quot;)

(change your D_msg line as well:
Code:
D_MSG(&quot; Reviewing File, press @Esc to abort&quot;)

And I forgot the colors[] array and F4 definition so you could run it! put this snippet at the top of the code:

Code:
  Public Colors[20]
  Public F4

  COLORS[ 1] = &quot;GB+/B&quot;
  COLORS[ 2] = &quot;W/N&quot;
  COLORS[ 3] = &quot;B/W,W+/R&quot;
  COLORS[ 4] = &quot;GR+/B,W+/R&quot;
  COLORS[ 5] = &quot;W/GR+&quot;
  COLORS[ 6] = &quot;W/B,N/W,,W/B&quot;
  COLORS[ 7] = &quot;N/W,W+/B&quot;
  COLORS[ 8] = &quot;W+/B&quot;
  COLORS[ 9] = &quot;W/GB&quot;
  COLORS[10] = &quot;W/R&quot;
  COLORS[11] = &quot;N/W&quot;
  COLORS[12] = &quot;R/W&quot;
  COLORS[13] = &quot;GR+/B,W+/GR&quot;
  F4 = -3

So to reiterate here is the code in full:

Code:
PUBLIC COLORS[20]
PUBLIC F4
  COLORS[ 1] = &quot;GB+/B&quot;
  COLORS[ 2] = &quot;W/N&quot;
  COLORS[ 3] = &quot;B/W,W+/R&quot;
  COLORS[ 4] = &quot;GR+/B,W+/R&quot;
  COLORS[ 5] = &quot;W/GR+&quot;
  COLORS[ 6] = &quot;W/B,N/W,,W/B&quot;
  COLORS[ 7] = &quot;N/W,W+/B&quot;
  COLORS[ 8] = &quot;W+/B&quot;
  COLORS[ 9] = &quot;W/GB&quot;
  COLORS[10] = &quot;W/R&quot;
  COLORS[11] = &quot;N/W&quot;
  COLORS[12] = &quot;R/W&quot;
  COLORS[13] = &quot;GR+/B,W+/GR&quot;
  F4 = -3

Mody_Memo(MemoRead(&quot;C:\TextFile.txt&quot;))


FUNCTION MODY_MEMO
  ** this is a read / write memo edit function
  PARAMETER MSTRING
  PRIVATE MSTRING,Tp,Lt,Bt,Rt,WRAP,MACTFLG,OLDLINE
  PRIVATE MINSERT
  WRAP = 1
  Tp = 6
  Lt = 2
  Bt = 20
  Rt = 76
  DROP_BOX(Tp,Lt,Bt,Rt,17)
  D_MSG(&quot; Enter revised note, @F4 to save, @Esc to abort&quot;)
  SET CURSOR ON
  MSTRING = STRTRAN(MEMOEDIT(MSTRING,Tp+1,Lt+1,Bt-1,Rt-1,.T.,&quot;MEMOFUNC&quot;,(Rt-Lt)-1),CHR(26),&quot;&quot;)
  SET CURSOR OFF
  RETURN(MSTRING)


FUNCTION MEMOFUNC
  PARAMETERS MSTATUS,MROW,MCOL
  PRIVATE MSTATUS,MROW,MCOL,RETVAL
  RETVAL = 0
  IF MSTATUS = 3
    IF WRAP = 0
      WRAP = 1
      RETVAL = 34
    ENDIF
  ELSE
    IF MSTATUS = 0
      @ Bt,Lt+1 SAY &quot;Row:&quot;+STR(MROW,3)+&quot; Col:&quot;+STR(MCOL,3)
    ENDIF
    IF LASTKEY() = F4
      RETVAL = 23 && CTRL-W
    ENDIF
  ENDIF
  RETURN(RETVAL)


FUNCTION D_MSG
  PARAMETER MSG,MLINE,MLGTH
  PRIVATE MSG,MLINE,MLGTH
  PRIVATE OLDCOLOR,X,STRING,Y,VAL_STRING,Z
  DECLARE HI_LITE[20],HI_POS[20]
  IF PCOUNT() < 3
    MLGTH = 78
  ENDIF
  IF PCOUNT() < 2
    MLINE = 23
  ENDIF
  VOID=AFILL(HI_LITE,&quot;&quot;)
  VOID=AFILL(HI_POS,-1)
  OLDCOLOR=SETCOLOR(COLORS[10])
  RESTSCREEN(MLINE+1,2,MLINE+1,MLGTH,BGC(SAVESCREEN(MLINE+1,2,MLINE+1,MLGTH),8))
  STRING     =&quot;&quot;
  VAL_STRING =&quot;&quot;
  Y=0
  IF LEFT(MSG,1) <> &quot; &quot;
    MSG = &quot; &quot;+MSG
  ENDIF
  IF &quot;$&quot;$MSG .OR. &quot;@&quot;$MSG
    ** Scan string looking for Highlighters...
    FOR X =1 TO LEN(MSG)
      DO CASE
          ** Highlight next char only...
        CASE SUBSTR(MSG,X+Y,1) =&quot;$&quot;
          Y=Y+1
          HI_LITE[Y] =SUBSTR(MSG,X+Y,1)
          HI_POS[Y]  =X
          ** Highlight next word only...
        CASE SUBSTR(MSG,X+Y,1) =&quot;@&quot;
          Y=Y+1
          FOR Z =0 TO 10
            IF !(SUBSTR(MSG,X+Y+Z,1)$&quot; -,.>])&quot;)
              HI_LITE[Y] =HI_LITE[Y]+SUBSTR(MSG,X+Y+Z,1)
            ELSE
              Z =10
            ENDIF
          NEXT
          HI_POS[Y] =X
      ENDCASE
      STRING =STRING+SUBSTR(MSG,X+Y,1)
    NEXT
  ELSE
    STRING=MSG
  ENDIF
  ** Display the string...
  @ MLINE,1 SAY LEFT(STRING+SPACE(MLGTH-1),MLGTH-1)
  VOID=SETCOLOR(COLORS[11])
  ** Just do the highlights...
  FOR X =1 TO Y
    IF HI_POS[X] <> -1
      @ MLINE,HI_POS[X] SAY HI_LITE[X]
      ** Not using the VAL_string...
      ** VAL_STRING=VAL_STRING+HI_LITE[X]
    ELSE
      X =Y+1
    ENDIF
  NEXT
  VOID=SETCOLOR(OLDCOLOR)
  RETURN(STRING)

FUNCTION BGC
  PARAMETERS STRING,X
  ** pass the function the 'save screen' string and the ascii value to be used
  PRIVATE X,I,NEWSTRING
  ** invent a new string...
  NEWSTRING=&quot;&quot;
  FOR I = 1 TO LEN(STRING) STEP 2
    ** take each alternate char and add to new string...
    NEWSTRING = NEWSTRING+SUBSTR(STRING,I,1)+CHR(X)
  NEXT
  ** return the new string to the caller...
  RETURN(NEWSTRING)

FUNCTION DROP_BOX
  PARAMETERS T,L,B,R
  PRIVATE T,L,B,R,X,I
  *FOR X = T TO B
  RESTSCREEN(T+1,L+1,B+1,R+1,BGC(SAVESCREEN(T+1,L+1,B+1,R+1),8))
  *NEXT
  FOR X = T TO B
    @ X,L CLEAR TO X,R
    FOR I = 1 TO 20 && Short delay loop...
    NEXT I
  NEXT
  @ T,L TO B,R
  RETURN(.T.)

Regards

Griff
Keep [Smile]ing
 
The other good way to browse a text file is to pull it into a table and use dbedit (or Tbrowse) to view it.

For years, I used a variant on this to provide a print preview (not very wysiwyg but ok).

HTH

Regards

Griff
Keep [Smile]ing
 
This may be just what your looking for.
cFile is the text file you want to browse and must include the full path (if not in current directory) and filename with extention.
For Example:
TxtBrowse(&quot;c:\myfolder\myfile.txt&quot;)
It requires linking the Nanfor.lib which may be obtained at:

PROCEDURE TxtBrowse(cFile)

LOCAL cColor := SETCOLOR()
LOCAL cScreen:= SAVESCREEN(4,9,11,71)

@ 4,9 TO 11,71

FT_DFSETUP(cFile, 5, 10, 10, 70, 1,14, 1,;
CHR(27), .T., 5, 132, 4096)

FT_DISPFILE()

FT_DFCLOSE()
SETCOLOR(cColor)
RESTSCREEN(4,9,11,71,cScreen)
RETURN


This is a partial quote from the Norton Guide for the Nanfor.lib
Syntax:

FT_DFSETUP( <cInFile>, <nTop>, <nLeft>, <nBottom>, <nRight>,;
<nStart>, <nCNormal>, <nCHighlight>, <cExitKeys>, ;
<lBrowse>, <nColSkip>, <nRMargin>, <nBuffSize> ) -> nResult

Arguments:

<cInFile> - text file to display (full path and filename)
<nTop> - upper row of window
<nLeft> - left col of window
<nBottom> - lower row of window
<nRight> - right col of window
<nStart> - line to place highlight at startup
<nCNormal> - normal text color (numeric attribute)
<nCHighlight> - text highlight color (numeric attribute)
<cExitKeys> - terminating key list (each byte of string is a
key code)
<lBrowse> - act-like-a-browse-routine flag
<nColSkip> - col increment for left/right arrows
<nRMargin> - right margin - anything to right is truncated
<nBuffSize> - size of the paging buffer

Returns:

0 if successful, FError() code if not
 
Thanks...I can't wait to try these solutions.

 
I saw the fbrowse file mentioned on the oasis web site but there was no way to download it.
 
Click on the link on the top left of the spyglass icon to download the file.

Ian Boys
DTE Systems Ltd
 
All I get is the following page...no icon.

Zip Directory of fbrowse.zip
Length Method Size Ratio Date Time File Name
------- ------ ------- ----- ---------- ----- ---------
32870 Deflate 9373 72% 1996-07-22 21:32 fbrowse.prg
------- ------- ----- -------
32870 9373 71% 1

 
I've used Browse.com with good success.
Simply call Browse and pass the file name from the run command and works like a champ. One line of code!
good luck
 
That's what you get if you click on the icon, the bit up and to the left of it sends the file.

Do you want me to e-mail it to you? If so, what's your address?


Ian Boys
DTE Systems Ltd
 
Bozz,

I would appreciate it very much if you would email the file to fmbizzell@bizzell.net

Thanks,

Frank
 
i have a memo class if your interested, let me know

bobby
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top