Page 1 of 1

Opening 2 files at the same time

Posted: Sat Aug 13, 2005 11:59 am
by Seb McClouth
I never done this before and would like to know how this can be achieved.

It needs to use these:
  • Code: Select all

    value = FREEFILE

    Code: Select all

    OPEN FileName$ FOR xxxx (what should be here again?) AS value
    DO
    Input value, temp$
    IF left$(TEMP$, 12) ="needed_value" then FileName$2=right$(Temp$,len(Temp$-13)
    LOOP until EOF(1)
    close Value

    Code: Select all

    OPEN FileName$2 FOR APPEND AS value
    Print value, "Sumfin"
    close value
grtz
Seb

Posted: Sat Aug 13, 2005 12:18 pm
by Rattrapmax6
Not sure what you mean by using those codes, but to open 2 files at once:

Code: Select all

OPEN "File1.txt" FOR INPUT AS #1 'Open File 1
OPEN "File2.txt FOR OUTPUT AS #2 'Open File 2

INPUT #1, Stuff
PRINT #2, Stuff

CLOSE #1
CLOSE #2
That will open 2 files at once, and in this code read from 1 and rewrite into 2..

:wink:

Posted: Sat Aug 13, 2005 1:00 pm
by Seb McClouth
What I mean is that I have to open the first file, search into it for a certain string, e.g.: standardlog = etc/var/boot.log.
Then retrieve that line, retrieve "etc/var/boot.log" from it and then open "etc/var/boot.log"

grtz
Seb

Re: Opening 2 files at the same time

Posted: Sat Aug 13, 2005 8:20 pm
by Rattrapmax6
Okay.. then I believe this is how you'd go about that... :wink:

Code: Select all

f% = FREEFILE

OPEN FileName$ FOR INPUT AS #f%
DO
INPUT #f%, temp$
IF LEFT$(TEMP$, 12) ="needed_value" THEN 
    FileName2$ = RIGHT$(Temp$, LEN(Temp$-13)
END IF
LOOP UNTIL EOF(1)
CLOSE #f%

OPEN FileName2$ FOR APPEND AS #f%
PRINT #f%, "Sumfin"
CLOSE #f%

ah, okay two at once

Posted: Sat Aug 13, 2005 10:33 pm
by mennonite
'using freefile with two open files at once:

file01$="somefin"
file02$="somefine.lse"

f=freefile
open file01$ for input as f
g=freefile
open file02$ for output as g

do
if not eof(f) then line input #f, q$ 'load from file01$
print #g, q$ 'save to file02$
loop until eof(f)

close #g
close #f

i've never seen a well coded program that required freefile, but it is a cute function all the same. i wish there was an analog for the SCREEN command. (not the SCREEN function.)

on second thought

Posted: Sat Aug 13, 2005 10:39 pm
by mennonite
the above code doesn't do anything besides combine both of rattrapmax6's examples, now that i've read them. i wasn't paying attention to anything except whether they show how to open two files at once using freefile, which technically, neither do. although it was better to redo your own code with freefile, which has been done already :)

i still maintain that i've never seen a well coded program that needs freefile, but that's not to say such a program doesn't exist. at first it looks like a useful function, but i can't guess how it would be. maybe someone can explain that to me sometime, using a *real* example, a "i needed it because" example, instead of the obvious "maybe it would be useful this way" example, the only kind i could make for it. or maybe it becomes very, very useful with subs, only i think it would be just as easily simulated with a global variable? oh well...

Posted: Sun Aug 14, 2005 9:42 am
by Rattrapmax6
FreeFile allows you to view a file as a whole right? Like for BMP loaders, or viewing the rambled stuff in a EXE with out mesing it up.... but normal text files wouldn't really need it..

correct me if I'm wrong...

Posted: Sun Aug 14, 2005 10:35 am
by Z!re
FREEFILE retuns the next free file ID number..

As you cant open two files with the same ID, you use FREEFILE, and it'll always work.. no compatibility issues.

Posted: Sun Aug 14, 2005 4:45 pm
by {Nathan}
What would it do if you already had 16 files open? (I think 16 is the max, correct me if I am wronge)

Posted: Sun Aug 14, 2005 5:07 pm
by MystikShadows
lol allow me to correct you...;-)...or rather extend your knowledge ;-)

The number of files you can open is as determined by the files statement in your configuration (files = 255 would give you 255 opened files. default is 20)

Posted: Sun Aug 14, 2005 6:22 pm
by Z!re
QB maximizes the amount of open files to 255, even if you change it to 4096 in config.sys, qb still wont open them.

There's no documentation on what happens if FREEFILE fail, but I guess, since it's QB: Illegal function call

Posted: Mon Aug 15, 2005 11:59 am
by {Nathan}
Yup... damn QB errors...