473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How many files can be open at a given time?

I'm a novice using VB .NET . I'm trying to use 2 files to read a line write
the line and get the run time error
"..exception of type 'System.IO.IOException.....additional information:
File already open."

It seems the error message is telling me VB can have only 1 file open at a
time. Tell me that's not true and where
I'm going wrong, please.

The code is:

Imports System.IO.File
..
..
..
..
private sub bRun_Click(byval sender as System.Object, byval e as
System.Event.Args) handles bRun.Click)

dim infil as integer = FreeFile()
dim outfil as integer = FreeFile()
dim infilname as string = "c"\red.txt"
dim outfilname as string = "c"\wrt.txt"
dim inline as string

FileOpen(outfil, outfilname,OpenMode.Output)
FileOpen(infil,infilname,OpenMode.Input) 'this is where error
occurs

while not eof(infil)
inline = LineInput(infil)
PrintLine(outfil,inline)
end while

FileClose(infil)
FileClose(outfil)

end sub
Thanks for your time, J e r

Nov 20 '05 #1
7 2369
Cor
Hi Jer,

I can give you an answer on your code (you can a lot of files open in the
same time), but this is very classic VB, when you are not writting something
that has to be converted, have than a look at streamreader and streamwriter
class.

I hope this helps

Cor
I'm a novice using VB .NET . I'm trying to use 2 files to read a line write the line and get the run time error
"..exception of type 'System.IO.IOException.....additional information:
File already open."

It seems the error message is telling me VB can have only 1 file open at a
time. Tell me that's not true and where
I'm going wrong, please.

The code is:

Imports System.IO.File
.
.
.
.
private sub bRun_Click(byval sender as System.Object, byval e as
System.Event.Args) handles bRun.Click)

dim infil as integer = FreeFile()
dim outfil as integer = FreeFile()
dim infilname as string = "c"\red.txt"
dim outfilname as string = "c"\wrt.txt"
dim inline as string

FileOpen(outfil, outfilname,OpenMode.Output)
FileOpen(infil,infilname,OpenMode.Input) 'this is where error occurs

while not eof(infil)
inline = LineInput(infil)
PrintLine(outfil,inline)
end while

FileClose(infil)
FileClose(outfil)

end sub

Nov 20 '05 #2
Right here is the most probable scenario !

You write some code which opens a file right !, then it fails or you are
debugging it and terminate it before you close it. OR you forget to close it
in code.

Then you change something and run the code again, you get the error message
because you already left it open.

Regards - OHM



J e r wrote:
I'm a novice using VB .NET . I'm trying to use 2 files to read a
line write the line and get the run time error
"..exception of type 'System.IO.IOException.....additional
information: File already open."

It seems the error message is telling me VB can have only 1 file open
at a time. Tell me that's not true and where
I'm going wrong, please.

The code is:

Imports System.IO.File
.
.
.
.
private sub bRun_Click(byval sender as System.Object, byval e as
System.Event.Args) handles bRun.Click)

dim infil as integer = FreeFile()
dim outfil as integer = FreeFile()
dim infilname as string = "c"\red.txt"
dim outfilname as string = "c"\wrt.txt"
dim inline as string

FileOpen(outfil, outfilname,OpenMode.Output)
FileOpen(infil,infilname,OpenMode.Input) 'this is where
error occurs

while not eof(infil)
inline = LineInput(infil)
PrintLine(outfil,inline)
end while

FileClose(infil)
FileClose(outfil)

end sub
Thanks for your time, J e r


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #3
Cor
OHM
dim infil as integer = FreeFile()
dim outfil as integer = FreeFile()


I even did not check it but was that not
1 and 2 or something?

Cor
Nov 20 '05 #4
* "J e r" <mi*****@localnet.com> scripsit:
I'm a novice using VB .NET . I'm trying to use 2 files to read a line write
the line and get the run time error
"..exception of type 'System.IO.IOException.....additional information:
File already open."

It seems the error message is telling me VB can have only 1 file open at a
time. Tell me that's not true and where
I'm going wrong, please.

The code is:

Imports System.IO.File
.
.
.
.
private sub bRun_Click(byval sender as System.Object, byval e as
System.Event.Args) handles bRun.Click)

dim infil as integer = FreeFile()
dim outfil as integer = FreeFile()
dim infilname as string = "c"\red.txt"
dim outfilname as string = "c"\wrt.txt"
dim inline as string

FileOpen(outfil, outfilname,OpenMode.Output)
FileOpen(infil,infilname,OpenMode.Input) 'this is where error
occurs

while not eof(infil)
inline = LineInput(infil)
PrintLine(outfil,inline)
end while

FileClose(infil)
FileClose(outfil)


The code should work, but the filenames are invalid. Maybe the files
are opened by an other application?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
Sorry I did not see the code before down the page. Here is the solution. The
original code could not have worked because the way FreeFile works is to
give you the next available File handle. As you had not used the first
available handle before asking for the next one, the same number would have
been given. '1'.

Here is the amended code. ( tested )

Dim infilname As String = "c:\MyIn.txt"
Dim outfilname As String = "c:\MyOut.txt"
Dim inline As String

infil = FreeFile()

FileOpen(infil, infilname, OpenMode.Input) 'this is where error occurs()

outfil = FreeFile()

FileOpen(outfil, outfilname, OpenMode.Output)

Regards - OHM


One Handed Man [ OHM# ] wrote:
Right here is the most probable scenario !

You write some code which opens a file right !, then it fails or you
are debugging it and terminate it before you close it. OR you forget
to close it in code.

Then you change something and run the code again, you get the error
message because you already left it open.

Regards - OHM



J e r wrote:
I'm a novice using VB .NET . I'm trying to use 2 files to read a
line write the line and get the run time error
"..exception of type 'System.IO.IOException.....additional
information: File already open."

It seems the error message is telling me VB can have only 1 file open
at a time. Tell me that's not true and where
I'm going wrong, please.

The code is:

Imports System.IO.File
.
.
.
.
private sub bRun_Click(byval sender as System.Object, byval e as
System.Event.Args) handles bRun.Click)

dim infil as integer = FreeFile()
dim outfil as integer = FreeFile()
dim infilname as string = "c"\red.txt"
dim outfilname as string = "c"\wrt.txt"
dim inline as string

FileOpen(outfil, outfilname,OpenMode.Output)
FileOpen(infil,infilname,OpenMode.Input) 'this is where
error occurs

while not eof(infil)
inline = LineInput(infil)
PrintLine(outfil,inline)
end while

FileClose(infil)
FileClose(outfil)

end sub
Thanks for your time, J e r


Regards - OHM# OneHandedMan{at}BTInternet{dot}com


Regards - OHM# OneHandedMan{at}BTInternet{dot}com
Nov 20 '05 #6
Thanks OHM!

And thanks to all who responded.

Your response time is the best.

Have a Merry Christmas, J e r
Nov 20 '05 #7
Errata (after testing the code):

Notice that I have changed the order of the commands:

* hi***************@gmx.at (Herfried K. Wagner [MVP]) scripsit:
private sub bRun_Click(byval sender as System.Object, byval e as
System.Event.Args) handles bRun.Click)

dim outfil as integer = FreeFile() dim infilname as string = "c"\red.txt"
dim outfilname as string = "c"\wrt.txt"
dim inline as string

FileOpen(outfil, outfilname,OpenMode.Output) dim infil as integer = FreeFile() FileOpen(infil,infilname,OpenMode.Input) 'this is where error
occurs

while not eof(infil)
inline = LineInput(infil)
PrintLine(outfil,inline)
end while

FileClose(infil)
FileClose(outfil)


--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lawrence | last post by:
2 Questions: 1.) Can anyone think of a way to speed up this function? It is terribly slow. I plan to reduce the number of directories to 3, which I guess will speed it up in the end. 2.) This...
5
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
11
by: MM | last post by:
Hi I have never written any C programs before, but it seems that I need to do so now. Hope some of you out there can spend a few minutes and help me by writing a simple example of something...
14
by: padh.ayo | last post by:
Can C open (and keep open) two files at any given time? so, FILE *a, *b; a = fopen(argv, "r"); b = fopen(argv, "r"); ?
7
by: Lee | last post by:
Hey all, I'm using the following code to send stuff accross the network, appologies for it being in full, but I've really no idea exactly where this error is occuring. =======network...
7
by: pike | last post by:
db2 8.1 FP11 on AIX 5.3.0.0 . The db2diag.log is intermittently reporting EMFILE (24) "Too many open files" errors. The culprit is always db2hmon. Sample db2diag.log output follows: ...
7
by: mosscliffe | last post by:
I have 4 text files each approx 50mb. I need to join these into one large text file. I only need to do this very occasionally, as the problem has occurred because of upload limitations. ...
10
by: kimiraikkonen | last post by:
Hi, I have an app which has a listbox and when i double click an associated fileS, i want their paths to be added into listbox in my application. This code works good when i try to open a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.