Reading a part of text file.

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
Guest

Reading a part of text file.

Post by Guest »

I have a txt file and there is 50 lines and in each line has 50 ascii marks.

How i can read ascii marks on area that is lines 20-30 and rows 10-15?

Hope you get what i mean.
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Hmm... you can't with QB but I do know how you can. If you know maps with rpgs darkdread style then this will be very easy for you. Follow the steps and there you go.

1. In between every character, put a comma (I don't know any faster way, sorry)

2. DIMension the array (1 TO 50, 1 TO 50)

3. Load the file into the array the same way you would a map.

Code: Select all

FOR y = 1 to 50
FOR x = 1 to 50
INPUT Array(X, Y)
NEXT
NEXT
Now your file is in the computers ram.

4. Read it the same way you would a map.

Code: Select all

FOR Y = 20 TO 30
FOR X = 10 TO 15
Array(X, Y) = ....
NEXT
NEXT
That will give you the charectars you want. I would reccoment putting them in a new array if you are using them more than once. Otherwise, this will do if you are doing something really simple (like printing it to a screen)
Image
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Sure you can with QB. If it's an ASCII file, all you need to know how to do is:

1. Keep track of line numbers (hint: use variables)
2. Know how to use MID$
3. Know how to use LINE INPUT
4. Knowledge of fixed-length strings might help if all the lines are of the same size, otherwise, just knowing how to work with strings is all you need

It's quite elementary, really. :D
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

I hate you... grrr... hey, it was early. I like to take the long ways sometimes, anyway. It's also fun to confuse noobies sometimes.
Image
User avatar
lurah-
Veteran
Posts: 206
Joined: Mon Nov 01, 2004 10:47 am
Location: Finland
Contact:

Post by lurah- »

Nathan. i coded with basic before even you were born. Sorry if i was gone like a years...
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

I have no idea what the relevance to that could possibly be. :shock:
User avatar
lurah-
Veteran
Posts: 206
Joined: Mon Nov 01, 2004 10:47 am
Location: Finland
Contact:

Post by lurah- »

Nathan1993 wrote: anyway. It's also fun to confuse noobies sometimes.
Something like that...[Edit]...grow up.[/Edit] :wink:
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

... :cry: leave me alone! *calls 911* Hello, operater, I am being harrassed by some guy...

Hey, it is still fun to confuse people. Plus, I don't see many tutors by you. And I'am only 11, so give me a freakin brake already *runs of crying and goes start playing Grand Theft Auto: San Andreas*

:cry: Give me a break!!!
Image
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

Now, I am off to go play San Andreas (I just got done crying)
Image
Post Reply