REALLY TOUGH QUESTION 
Author Message
 REALLY TOUGH QUESTION

You can't avoid the chr$(26) stopping a file open for input. The best
thing is to open it in binary mode. That is much more flexible that
random.

If you have to stick with opening the file for input, you are stuck!

ATB

Charles Kincaid


Quote:
>Well, all my life I've asked stupid questions, but here goes a good (and
>very difficult one).

>I'm trying to read from a sequential file.  The file is supposed to be
>of any type (HTML, TXT, GIF, JPG, MID, MP3, anything), and therefore,
>has a TON of weird extended ASCII chars.  The problem is, when reading
>from the file, if it detects chr$(26), it will flag this as the end of
>file, and will not read beyond this point.

>I've tried opening a RANDOM file and (using a user-defined type and the
>GET command), managed to get QB to read Chr$(26) without going EOF on
>me, but I'd rather not have to rewrite the code, making it a RANDOM
>file.

>I know chr$(26) IS the EOF character, but I was hoping there'd be a way
>around it.

>Is there any hope for me????

>Thanks anyway,

>Brandon Bagwell




Tue, 04 Jun 2002 03:00:00 GMT  
 REALLY TOUGH QUESTION
Well, all my life I've asked stupid questions, but here goes a good (and
very difficult one).

I'm trying to read from a sequential file.  The file is supposed to be
of any type (HTML, TXT, GIF, JPG, MID, MP3, anything), and therefore,
has a TON of weird extended ASCII chars.  The problem is, when reading
from the file, if it detects chr$(26), it will flag this as the end of
file, and will not read beyond this point.

I've tried opening a RANDOM file and (using a user-defined type and the
GET command), managed to get QB to read Chr$(26) without going EOF on
me, but I'd rather not have to rewrite the code, making it a RANDOM
file.

I know chr$(26) IS the EOF character, but I was hoping there'd be a way
around it.

Is there any hope for me????

Thanks anyway,

Brandon Bagwell



Wed, 05 Jun 2002 03:00:00 GMT  
 REALLY TOUGH QUESTION
Ok,  so you are probably reading one character at a time, right?

So the only change to the code (re-writing part) is how the file
is opened and fielded (???)

Whaza big deal about that?



Wed, 05 Jun 2002 03:00:00 GMT  
 REALLY TOUGH QUESTION

Quote:

>Well, all my life I've asked stupid questions, but here goes a good (and
>very difficult one).

>I'm trying to read from a sequential file.  The file is supposed to be
>of any type (HTML, TXT, GIF, JPG, MID, MP3, anything), and therefore,
>has a TON of weird extended ASCII chars.  The problem is, when reading
>from the file, if it detects chr$(26), it will flag this as the end of
>file, and will not read beyond this point.

Open and read the file in BINARY mode, or, test the extention and open as is
required.

   ____    _    ____      ____  _____
  |  _ \  / \  / ___) __ | ___)(_   _) Don Schullian

  |____//_/ \_\(____/\__/|_|     |_|    www.DASoftVSS.com
  ___________________________________   www.basicguru.com
      Vertical Software Solutions



Thu, 06 Jun 2002 03:00:00 GMT  
 REALLY TOUGH QUESTION

Quote:
> Ok,  so you are probably reading one character at a time, right?

> So the only change to the code (re-writing part) is how the file
> is opened and fielded (???)

> Whaza big deal about that?

'za big deal is knowing when you've reached the real end of the file.

After all you can't use EOF( ) now.  But there are two functions which will
help LOF( ) -- Length Of File -- which tells you how many bytes there are in
a file, and LOC() -- Location Of Cursor -- which tells you how far through
the file you have read so far.

You can either read the file several bytes at a time and use a

    FOR J = 1 TO LOF(file) STEP several
        LET T$ = Input$(several, file)
        ...
    NEXT

loop or you can read it a "chunk" at a time and use a

    DO WHILE LOC(file) <= LOF(file)
        LET T$ = SPACE$(chunksize)
        GET #file, T$
        ...
    LOOP

or some variation on either of them.

Cheers

Derek



Thu, 06 Jun 2002 03:00:00 GMT  
 REALLY TOUGH QUESTION
Actually, you CAN use EOF with a file opened in BINARY mode; however, EOF()
is not true until AFTER an unsuccessful read (GET). With sequential I-O
(INPUT#) EOF()  will be true BEFORE a read.

However, your idea of keeping track of LOF and SEEK (preferred to LOC) is
the superior practical method of reading the file, the whole file and
nothing but the file.

--
Michael Mattias
Racine WI USA

Quote:

>'za big deal is knowing when you've reached the real end of the file.

>After all you can't use EOF( ) now.  But there are two functions which will



Thu, 06 Jun 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. A REALLY tough question!

2. Really tough one

3. Really really stuck on this one. (QBasic Question)

4. This is a really really dumb question.

5. HELP - Really, really simple printer questions

6. Really, really stupid question.

7. Really, Really Horrible question about sprites

8. tough question for gurus!

9. Tough questions...

10. Mathmatical Genious Needed for this tough question

11. TOUGH Question - Late Bound COM objects and VB.NET

12. tough question for powerbasic

 

 
Powered by phpBB® Forum Software