
-----------------------------------
gnarky
Mon Mar 21, 2005 8:09 pm

First Run Works, Second Doesn't...hmmm
-----------------------------------
Alrite, so I have my program. Its a database program. A user enters a username and then password. These are written into a database. I run it once. Perfect! And then I do it again, no dice. It shows up an error saying "I/O attempted upopened or closed stream"...

File.Copy ("blank.txt","temp.txt")
var stream,stream2,lastnumber :int 
var username, password, answer:string
  

%Gets the username and password from the user
%Enters the information into a tempory file

loop
put "Username: ".. 
get username
put "Password: "..       
get password
cls 
    open : stream,"temp.txt",put 
    put : stream, username, " "
    put : stream, password, " " 
    close : stream
    
% Confirms the user's name and password

put ""
put "Username: ".. 
put username(1) 
put "Password: ".. 
put password(1)
put "(Y/N)" 
get answer 
exit when answer="y"
cls
    end loop
    
% Opens the data file, gets all previous entries
open : stream, "data.txt", get
    get : stream, lastnumber
        var words:array 1..lastnumber of string     
for i : 1 .. lastnumber  
    get : stream, words (i):*
    close : stream

    open : stream, "data.txt", put
    put : stream, lastnumber + 1, " "..
    put : stream, username, " "..
    put : stream, password
    put : stream, lastnumber, " "..
    put : stream, words (i)
    close : stream
    
    end for


-----------------------------------
Delos
Mon Mar 21, 2005 8:13 pm


-----------------------------------

get : stream, words (i):*
close : stream


The reason it says you have an "unopened or closed stream" is because you've closed the stream.  Take out the 'close' part.

-----------------------------------
gnarky
Mon Mar 21, 2005 8:18 pm


-----------------------------------
It need that though...It says that 'stream is already opened'

-----------------------------------
StarGateSG-1
Mon Mar 21, 2005 11:55 pm


-----------------------------------
You need to clsoe it atfer the end of the for loop
