Me again

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

Post Reply

Am I boring?

YEAH!!!
1
20%
No
4
80%
 
Total votes: 5

izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Me again

Post by izidor »

First:

Why a string has fixed number of characters?
I tried this:

Code: Select all

DIM s AS STRING * 10000
INPUT a
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 »

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! :(
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

# 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!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Post by izidor »

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
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

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 #.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Post by izidor »

I am trying to create text editor.
Post Reply