Reading from Files?

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
SCC
Coder
Posts: 12
Joined: Mon Oct 09, 2006 9:53 pm

Reading from Files?

Post by SCC » Sat Dec 09, 2006 2:36 pm

I've been working with the Qbasic BootCamp tut series, and i've read 4 pages and did the assignments. Now i'd like to take a break from learning and try to use some of it on a project.

One problem i had from the start is reading from files. From what the tut says, i can only read one line, or read numerical data into an array. What i needed to do was read an entire SUB from a file.

I've got a fair-sized graphic designed (one of what is going to be quite a few of them), and it takes up not a few lines, and i don't want the main program flooded with all that. It would be much easier to just write a txt file and read it into it, but i just can't seem to figure out how that works.

I used to use a program called DarkBASIC that had a command called APPEND, then i just called the SUB name and it read all the commands, but i don't think qbasic has anything like that, does it?

If not, is there anything else i can do here? This is all assuming SUBS use up the size limit, which i don't know if it does or not.

RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton » Sat Dec 09, 2006 3:18 pm

It is possible to create two files, and compile them together, but it is complicated, a much easier way is to change to FreeBasic

SCC
Coder
Posts: 12
Joined: Mon Oct 09, 2006 9:53 pm

Post by SCC » Sat Dec 09, 2006 4:47 pm

I'd rather keep learning in Qbasic for the moment at least, this is the first time i'm actually retaining all this info and getting some programs working.


Anyways, I figured it out :D '$INCLUDE: 'code.txt'

Guess it's a library command, but it worked pretty good here, hehe.

RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton » Sat Dec 09, 2006 7:22 pm

fb is the modern version of qb, there are almost no differences

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Sat Dec 09, 2006 7:51 pm

SCC wrote:......
Anyways, I figured it out :D '$INCLUDE: 'code.txt'

Guess it's a library command, but it worked pretty good here, hehe.
Actually, $INCLUDE is not a library command, it's what Basic calls a metacommand. It provides a nice, simple way for programs to be able to share some common code. Most languages have similar facilities. COBOL calls these "copyfiles".

An INCLUDE inserts the entire block of code from the specified text file. There are some restrictions as to what code can be included.

Some languages have MACRO libraries which allow you to insert a block of customized source code based on provided parameters.

Other languages, including QuickBasic, allow you include a function or a SUB from a library. Only the call to the function or SUB actually appears in your source code, and the required code is LINKED into your executable program. That is, you don't actually see it as part of your source code.

Regards..... Moneo

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Sat Dec 09, 2006 7:57 pm

RayBritton wrote:fb is the modern version of qb, there are almost no differences
For crying out loud, Ray, you sound like a Jesus freak! You're like an evangelist who keeps pounding us with FreeBasic. It can get really annoying. Don't you have anything original to share in your posts?

*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.

User avatar
sid6.7
Veteran
Posts: 318
Joined: Tue Jun 21, 2005 8:51 am
Location: west USA
Contact:

Post by sid6.7 » Sun Dec 10, 2006 12:09 am

SCC wrote:I'd rather keep learning in Qbasic for the moment at least, this is the first time i'm actually retaining all this info and getting some programs working.


Anyways, I figured it out :D '$INCLUDE: 'code.txt'

Guess it's a library command, but it worked pretty good here, hehe.
good job i'm the same way....i want to learn all i can from qb
then i'll try something else...i still have VERY far to go..

SCC
Coder
Posts: 12
Joined: Mon Oct 09, 2006 9:53 pm

Post by SCC » Sun Dec 10, 2006 9:56 pm

All i originally wanted to do was make one of those graphical text adventure games, like the one in that movie 'Big', but i guess i'll be in it for the long haul and learn to make something worthwhile. :)

Post Reply