log in | register | forums
Show:
Go:
Forums
Username:

Password:

User accounts
Register new account
Forgot password
Forum stats
List of members
Search the forums

Advanced search
Recent discussions
- Elsear brings super-fast Networking to Risc PC/A7000/A7000+ (News:)
- Latest hardware upgrade from RISCOSbits (News:)
- Announcing the TIB 2024 Advent Calendar (News:1)
- Code GCC produces that makes you cry #12684 (Prog:39)
- RISCOSbits releases a new laptop solution (News:)
- Rougol November 2024 meeting on monday (News:)
- Drag'n'Drop 14i1 edition reviewed (News:)
- WROCC November 2024 talk o...ay - Andrew Rawnsley (ROD) (News:2)
- October 2024 News Summary (News:3)
- RISC OS London Show Report 2024 (News:1)
Latest postings RSS Feeds
RSS 2.0 | 1.0 | 0.9
Atom 0.3
Misc RDF | CDF
 
View on Mastodon
@www.iconbar.com@rss-parrot.net
Site Search
 
Article archives
Acorn Arcade forums: Programming: Read tes=xt files in BASIC
 
  Read tes=xt files in BASIC
  (19:02 1/8/2001)
  Matthew (13:58 15/6/2002)
    rich (10:05 2/8/2001)
      Matthew (13:58 15/6/2002)
  RevinKevin (13:58 15/6/2002)
    monkeyson (13:58 15/6/2002)
      RevinKevin (13:58 15/6/2002)
        RevinKevin (15:20 15/9/2001)
 
RevinKevin Message #4801, posted at 19:02, 1/8/2001
Unregistered user Is it possible to read a text file in BASIC and
display the info on screen e.g
A text file contains word 1, word 2 word 3 etc

And the BASIC program would print word 1
then word 2 on the next line and so on.

Thanks

  ^[ Log in to reply ]
 
rich Message #4803, posted at 10:05, 2/8/2001, in reply to message #4802
Unregistered user
That's from memory, so could be wrong (I'm not at home currently and have a horrible feeling about the while loop)

I usually use...

in%=OPENIN "ADFS::4.$.file"
REPEAT
  line$=GET$#in%
  PRINT line$
UNTIL EOF#in%
CLOSE#in%

  ^[ Log in to reply ]
 
RevinKevin Message #4808, posted at 15:20, 15/9/2001, in reply to message #4807
Unregistered user Thanks to all who replied to my earlier questions.

The results can be found on my web page
http://www.oberon.spaceports.com/~kevsite/Computing

And is called info. Any comments and tips for improvements will be greatfully recceived.

  ^[ Log in to reply ]
 
Matthew Message #4802, posted at 13:58, 15/6/2002, in reply to message #4801
Unregistered user
Is it possible to read a text file in BASIC and display the info on screen e.g A text file contains word 1, word 2 word 3 etc

And the BASIC program would print word 1 then word 2 on the next line and so on.

You need something like this (assuming the text file has one word per line like you want the output) :

I%=OPENIN("textfile" )
WHILE NOT EOF#I%
  A$=GET$#I%
  PRINT A$
ENDWHILE

That's from memory, so could be wrong (I'm not at home currently and have a horrible feeling about the while loop...), but it's the sort of thing you want to be doing. smile Try typing HELP OPENIN etc. at the BASIC prompt to get some pointers, and there's a StrongHelp BASIC manual downloadable from http://www.users.zetnet.co.uk/kappa/Strong/basic.htm

ATB,
Matthew

  ^[ Log in to reply ]
 
Matthew Message #4804, posted at 13:58, 15/6/2002, in reply to message #4803
Unregistered user
I usually use...

in%=OPENIN
"ADFS::4.$.file"
REPEAT
  line$=GET$#in%
  PRINT line$
UNTIL EOF#in%
CLOSE#in%

But with this version, something is printed even if the file is empty, which you probably don't want.

BTW, I have checked and my WHILE look is okay. smile But I forgot the vital CLOSE#I% at the end which closes the open file.

ATB,
Matthew

  ^[ Log in to reply ]
 
RevinKevin Message #4805, posted at 13:58, 15/6/2002, in reply to message #4801
Unregistered user Thanks

That works.
But is it possible to have a relitive file location
i.e instead of ADFSDisc4tonguerog.textfile
just have texttile

Because the textfile will be in the same directory as the progarm.

Thanks

  ^[ Log in to reply ]
 
monkeyson Message #4806, posted at 13:58, 15/6/2002, in reply to message #4805
Unregistered user If you create an Obey file, with something like

Set ilikemonkeys$dir <Obey$Dir>
Wimpslot -min 32k -max 32k
<ilikemonkeys$dir>.BasicFile

- replace the 32k with the amount of memory needed by your program, and ilikemonkeys with something more sensible...

Then you can do
f = OPENIN("<ilikemonkeys$Dir>.Textfile"wink

from your program

  ^[ Log in to reply ]
 
RevinKevin Message #4807, posted at 13:58, 15/6/2002, in reply to message #4806
Unregistered user Thanks thats just what I wanted smile
  ^[ Log in to reply ]
 

Acorn Arcade forums: Programming: Read tes=xt files in BASIC