954,153 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

QBasic opening notepad files

I am having trouble getting the right code to look at a .txt file and print a random word from a list, going down the .txt file. I can get it to open the file which i think is:
OPEN "whatever" FOR INPUT AS ?
and then print ?
I am a bit stuck. Sorry if the question is hard to understand. Thanks
TP :rolleyes:
Oh, by the way, this is in QBASIC!

Tom Pilk
Newbie Poster
14 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

CLS
RANDOMIZE TIMER
OPEN "test.txt" FOR INPUT AS #1
DIM wds$(1000)
count% = 0
WHILE NOT EOF(1)
LINE INPUT #1, LL$
FOR K% = 1 TO LEN(LL$)
IF MID$(LL$, K%, 1) = " " OR K% = LEN(st$) THEN
count% = count% + 1
wds$(count%) = RTRIM$(MID$(LL$, LastK% + 1, K% - LastK%))
LastK% = K%
END IF
NEXT K%
test% = RND * count%

PRINT wds$(test%)
FOR K% = 1 TO count%: wds$(K%) = "": NEXT
count% = 0: LastK% = 0
WEND
CLOSE #1

Buff
Light Poster
40 posts since May 2004
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You