Simple textfile to array loader

General FreeBASIC programming questions.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Simple textfile to array loader

Post by mrminecrafttnt »

My Question is is that the correct method to load a textfile in an arrey?

Code: Select all

open "loadme.txt" for input access read as #1
if lof(1)=0 then print "Make a ""loadme.txt"" first." : sleep :end
redim load(any) as string
dim payload as string
Print "loading.."
do
    input #1,payload
    if payload <> "" then
        print ubound(load)
        redim preserve load(ubound(load)+1)
        load(ubound(load))=payload
    end if        
loop until eof(1) = -1
close #1
Print "Strings:";ubound(load)
Print "OUTPUT :"
for i as integer = lbound(load) to ubound(load)
    print load(i)
next
sleep
fxm
Moderator
Posts: 12081
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Simple textfile to array loader

Post by fxm »

If you don't want to split a text line in the file if a delimiter (comma) is encountered in the line, use 'line input #' rather than 'input #'.
(see documentation)

In addition:
Print "Strings:";ubound(load) - lbound(load) + 1
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Re: Simple textfile to array loader

Post by mrminecrafttnt »

fxm wrote: Jun 05, 2022 18:28 If you don't want to split a text line in the file if a delimiter (comma) is encountered in the line, use 'line input #' rather than 'input #'.
(see documentation)

In addition:
Print "Strings:";ubound(load) - lbound(load) + 1
Thanks! :)
Post Reply