If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!
Moderators: Pete , Mods
izidor
Veteran
Posts: 110 Joined: Wed Apr 22, 2009 3:13 am
Contact:
Post
by izidor » Fri Jul 10, 2009 7:20 am
First:
Why a string has fixed number of characters?
I tried this:
But the text stops at 4 row.
Second:
How to open whole text not just one row with OPEN statement?
Code: Select all
OPEN "abc.txt" for input as #1
input #1,a$
print a$
Harry Potter
Veteran
Posts: 111 Joined: Sat Feb 21, 2009 8:19 am
Location: New York, U.S.
Post
by Harry Potter » Fri Jul 10, 2009 11:32 am
How to open whole text not just one row with OPEN statement?
Try this:
Code: Select all
OPEN "file.txt" FOR INPUT AS #1
S$=INPUT$(LOF(#1),#1)
CLOSE #1
Joseph Rose, a.k.a. Harry Potter
Creating magic in the computer community...or at least striving to!
burger2227
Veteran
Posts: 2466 Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Post
by burger2227 » Fri Jul 10, 2009 12:21 pm
# is not required in the INPUT$ Function or the EOF function.
Syntax: INPUT$(bytes, filenumber)
If the string exceeds 32,767 characters(bytes) there will be a string error!
So check the LOF(1) first!
izidor
Veteran
Posts: 110 Joined: Wed Apr 22, 2009 3:13 am
Contact:
Post
by izidor » Sun Jul 12, 2009 12:15 pm
Code: Select all
OPEN "file.txt" FOR INPUT AS #1
a$=INPUT$(LOF(1),#1)
PRINT a$
CLOSE #1
This works fine, but are there any ideas for the first one?
Thanks
burger2227
Veteran
Posts: 2466 Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA
Post
by burger2227 » Sun Jul 12, 2009 12:32 pm
Do you mean the fixed length string? Fixed length strings are required in Random file record fields. You can define them in a TYPE definition or a FIELD statement.
Why are you using one anyhow? Anything over 1000 characters (1000 bytes) will be lost. INPUT # is used in sequencial files normally and has problems with commas in number values. LINE INPUT # is used to read entire lines of a file as variable length text. It has no problems with commas. In fact it can return a line of data with any quotes from a file created by WRITE #.
izidor
Veteran
Posts: 110 Joined: Wed Apr 22, 2009 3:13 am
Contact:
Post
by izidor » Tue Jul 14, 2009 8:43 am
I am trying to create text editor.