Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 First Run Works, Second Doesn't...hmmm
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gnarky




PostPosted: Mon Mar 21, 2005 8:09 pm   Post subject: 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"...

code:
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 "<-Cofirm->"
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
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Mar 21, 2005 8:13 pm   Post subject: (No subject)

code:

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




PostPosted: Mon Mar 21, 2005 8:18 pm   Post subject: (No subject)

It need that though...It says that 'stream is already opened'
StarGateSG-1




PostPosted: Mon Mar 21, 2005 11:55 pm   Post subject: (No subject)

You need to clsoe it atfer the end of the for loop
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: