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
"..exceptio n of type 'System.IO.IOEx ception.....add itional 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(byva l sender as System.Object, byval e as
System.Event.Ar gs) 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,Open Mode.Output)
FileOpen(infil, infilname,OpenM ode.Input) 'this is where error
occurs
while not eof(infil)
inline = LineInput(infil )
PrintLine(outfi l,inline)
end while
FileClose(infil )
FileClose(outfi l)
end sub
Thanks for your time, J e r 7 2401
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 "..exceptio n of type 'System.IO.IOEx ception.....add itional 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(byva l sender as System.Object, byval e as System.Event.Ar gs) 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,Open Mode.Output) FileOpen(infil, infilname,OpenM ode.Input) 'this is where
error occurs
while not eof(infil) inline = LineInput(infil ) PrintLine(outfi l,inline) end while
FileClose(infil ) FileClose(outfi l)
end sub
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 "..exceptio n of type 'System.IO.IOEx ception.....add itional 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(byva l sender as System.Object, byval e as System.Event.Ar gs) 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,Open Mode.Output) FileOpen(infil, infilname,OpenM ode.Input) 'this is where error occurs
while not eof(infil) inline = LineInput(infil ) PrintLine(outfi l,inline) end while
FileClose(infil ) FileClose(outfi l)
end sub
Thanks for your time, J e r
Regards - OHM# OneHandedMan{at }BTInternet{dot }com
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
* "J e r" <mi*****@localn et.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 "..exceptio n of type 'System.IO.IOEx ception.....add itional 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(byva l sender as System.Object, byval e as System.Event.Ar gs) 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,Open Mode.Output) FileOpen(infil, infilname,OpenM ode.Input) 'this is where error occurs
while not eof(infil) inline = LineInput(infil ) PrintLine(outfi l,inline) end while
FileClose(infil ) FileClose(outfi l)
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>
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.tx t"
Dim outfilname As String = "c:\MyOut.t xt"
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 "..exceptio n of type 'System.IO.IOEx ception.....add itional 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(byva l sender as System.Object, byval e as System.Event.Ar gs) 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,Open Mode.Output) FileOpen(infil, infilname,OpenM ode.Input) 'this is where error occurs
while not eof(infil) inline = LineInput(infil ) PrintLine(outfi l,inline) end while
FileClose(infil ) FileClose(outfi l)
end sub
Thanks for your time, J e r
Regards - OHM# OneHandedMan{at }BTInternet{dot }com
Regards - OHM# OneHandedMan{at }BTInternet{dot }com
Thanks OHM!
And thanks to all who responded.
Your response time is the best.
Have a Merry Christmas, J e r
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(byva l sender as System.Object, byval e as System.Event.Ar gs) 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,Open Mode.Output)
dim infil as integer = FreeFile()
FileOpen(infil, infilname,OpenM ode.Input) 'this is where error occurs
while not eof(infil) inline = LineInput(infil ) PrintLine(outfi l,inline) end while
FileClose(infil ) FileClose(outfi l)
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 seems to be the brute force method, and I'm wondering if
anyone can think of a better strategy. I've been asked to make life
easy on graphic designers by not making assumptions about where I
might find the files that the software might need to...
|
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 these files, I wish to do the same using another python code
instead of running each of these files one by one, which would be cumbersome
giving the argv of each file every single time.
This can be easily done using a shell script but I just...
|
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'
|
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 fairly similar to what I need. I
really think it is a simple matter if you know C programming, but to me it
is not easy at all. An example from some "professional" C programmer will
probably give me all I need to complete it into exactly what I need....
|
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");
?
| |
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 code============
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
|
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:
2007-03-20-07.42.35.269106+060 I14996239C505 LEVEL: Severe (OS)
PID : 2289758 TID : 772 PROC : db2hmon 0
INSTANCE: defser_t NODE : 000
FUNCTION: DB2 UDB, SQO Memory Management, sqlocshr2, probe:200
|
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.
Bearing in mind filesize and memory useage, would I be better reading
every line in every file and writing each line to the output file or
is there someway I could execute some shell command.
|
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 "single" file with my app
which works to get commandline arguments to get file paths:
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length 1 Then
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |