The commands you will use with frequency
for do this is:
OPEN, LINE INPUT, GET, PUT, EOF, LOF,
and the basic BASIC command.
Let's see one by one:
OPEN | OPEN "file" FOR [INPUT, OUTPUT, RANDOM, BINARY, APPEND]
AS #n
|
LINE INPUT | LINE INPUT #n, lin$
|
GET | GET #n, pos, dat$
|
PUT | PUT #n, pos, dat$
|
EOF | EOF(n)
|
LOF | LOF(n)
|
Now I will give some useful source that you can use, but please give me some credits!
* A better way to get all the data from the file:
OPEN file$ FOR INPUT AS #1
DO WHILE NOT EOF(1)
'Here is a loop that calculate
LINE INPUT #1, lin$
'the number of lines in the
lt = lt + 1
'file
LOOP
CLOSE #1
DIM lines$(lt)
'Here we dimension a array to
OPEN file$ FOR INPUT AS #1
'store the data
FOR i = 1 TO lt
LINE INPUT #1, lin$
lines$(i) = lin$
NEXT i
* A way to store an then get data in a file
'Here is the data you want to store
DATA 1,2,3,4,5
DATA 6,7,8,9,10
DATA 11,12,13,14,15
DATA 16,17,18,19,20
OPEN "datatest.dat" FOR OUTPUT AS #1
FOR i = 1 TO 4
READ a, b, c, d, e
lin$ = STR$(a) + "," + STR$(b) + "," + STR$(c)
lin$ = lin$ + "," + STR$(d) + "," + STR$(e) + ","
PRINT #1, lin$
NEXT i
CLOSE #1
'Simple command to close the
'file
OPEN "datatest.dat" FOR INPUT AS #1
DO WHILE NOT EOF(1)
LINE INPUT #1, lin$
FOR i = 1 TO LEN(lin$)
'Loop that goes from 1 to the
'the size of the read line
ch$ = MID$(lin$, i, 1)
'This command will get char
'by char from the line
IF ch$ = "," THEN
fd = fd + 1
GOTO jump
END IF
var$(fd) = var$(fd) + ch$
jump:
NEXT i
a = VAL(var$(0))
'Here we put the data on a
b = VAL(var$(1))
'array
c = VAL(var$(2))
d = VAL(var$(3))
e = VAL(var$(4))
PRINT a, b, c, d, e
FOR d = 0 TO 4
'We need to erase the data in
var$(d) = ""
'the temp array to use it
NEXT d
'again
fd = 0
LOOP
* Here is a program to find word in a text:
CLS
INPUT "Word to find: "; word$
INPUT "File to search: "; file$
CLS
OPEN file$ FOR INPUT AS #1
DO WHILE NOT EOF(1)
LINE INPUT #1, lin$
lt = lt + 1
LOOP
CLOSE #1
DIM lines$(lt)
OPEN file$ FOR INPUT AS #1
FOR i = 1 TO lt
LINE INPUT #1, lines$(i)
NEXT i
FOR i = 1 TO lt
FOR ii = 1 TO LEN(lines$(i)) - LEN(word$)
test$ = MID$(lines$(i), ii, LEN(word$))
IF test$ = word$ THEN
SOUND 1000, .5
CLS
LOCATE 1, 1: PRINT "Word founded
at line "; i; " at position "; ii
LOCATE 3, 1: PRINT "The line is:"
LOCATE 5, 1: PRINT lines$(i):
COLOR 14
LOCATE 5, ii: PRINT word$
COLOR 7
finds = finds + 1
LOCATE 7, 1: PRINT "Any key to continue"
SLEEP
END IF
NEXT ii
NEXT i
LOCATE 7, 1: PRINT "Total of words found: "; finds