Topics

Displaying the contents of a text file

Ian_Wade_G3NRW
 

Svein/Richard

Each of your approaches worked fine. Problem solved. Thank you both.

P.S. I had not realised you could concatenate all the lines into one variable (text$). In the extreme, the length of text$ in my program could be 600 lines x 80 chars/line = 48000 characters. Am I correct in assuming there is no limit to the length of text$ (until you run out of memory) in BB4W 6.00 and later?

--
Ian




***** TS-590 Family Resources Page: http://g3nrw.net/TS-590

On 12/05/2017 06:59, Richard Russell wrote:
On Thu, May 11, 2017 at 02:44 pm, Ian_Wade_G3NRW wrote:

I am trying to display the contents of a 600-line plain text file in
BB4W, in an editbox.

If you have a 'plain text file' (and I am assuming you mean a file that uses CRLF pairs as the line terminations) it is quite unnecessary to split it into its constituent lines before sending it to the edit control. It is simpler and quicker to keep it as a single 'unit':

file% = OPENIN("file.txt")
text$ = GET$#file% BY EXT#file%
CLOSE #file%
SYS "SetDlgItemText", !dlg%, 100, text$

It would only be necessary to split it into individual lines if you needed to change the line terminations from (say) LF to CRLF, i.e. it was a Linux-style text file.

The style bit for read-only is ES_READONLY

Richard.


Richard Russell
 

On Thu, May 11, 2017 at 02:44 pm, Ian_Wade_G3NRW wrote:
I am trying to display the contents of a 600-line plain text file in
BB4W, in an editbox.

If you have a 'plain text file' (and I am assuming you mean a file that uses CRLF pairs as the line terminations) it is quite unnecessary to split it into its constituent lines before sending it to the edit control.  It is simpler and quicker to keep it as a single 'unit':

      file% = OPENIN("file.txt")
      text$ = GET$#file% BY EXT#file%
      CLOSE #file%
      SYS "SetDlgItemText", !dlg%, 100, text$

It would only be necessary to split it into individual lines if you needed to change the line terminations from (say) LF to  CRLF, i.e. it was a Linux-style text file.

The style bit for read-only is ES_READONLY

Richard.


svein svensson
 

Hint :)

Svein


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DIM textLine$(600)
.
.
.
PROC_editbox(dlg%, "", 100, 160, 10, 500, 470, WS_VSCROLL + ES_MULTILINE + ES_READONLY)
.
.
.
FOR n% = 1 TO 600
text$+=textLine$(n%)+CHR$13+CHR$10
NEXT
SYS "SetDlgItemText", !dlg%, 100, text$
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ian_Wade_G3NRW
 

I am trying to display the contents of a 600-line plain text file in
BB4W, in an editbox.

Using "http://www.bbcbasic.co.uk/bbcwin/manual/bbcwing.html#editbox" as
a guide, my skeleton code is something like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DIM textLine$(600)
.
.
.
PROC_editbox(dlg%, "", 100, 160, 10, 500, 470, WS_VSCROLL + ES_MULTILINE)
.
.
.
FOR n% = 1 TO 600
SYS "SetDlgItemText", !dlg%, 100, textLine$(n%)
NEXT

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When I run this, vestiges of the text lines appear briefly at the top of
the editbox, then disappear.

I'm sure I have missed something very obvious. Any hints?

Also, the editbox is intended here for read-only display. How do I make
the editbox read-only?

--

Ian