Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Opening a File


Reply
 
Thread Tools Display Modes
  #1  
Old 12-17-2002, 10:18 AM
Thanatos's Avatar
Thanatos Thanatos is offline
Contributor
 
Join Date: Jul 2002
Location: New Paltz, NY
Posts: 447
Default Opening a File


Is there a way i can check to see if a file is currently in use prior to opening it? I want to avoid that runtime error.
Reply With Quote
  #2  
Old 12-17-2002, 11:27 AM
ALEX_0077's Avatar
ALEX_0077 ALEX_0077 is offline
Contributor
 
Join Date: Nov 2002
Location: American Canyon, CA
Posts: 622
Default

(If you mean 'an open file that your program opened...)

Sure!

(Of course i was going to say the obvious. )

In your code, always make sure to keep track of open files so that you can close them when your program stops. I know this isn't the prettiest way, but it is simple.

Example:

'IN your code you may have a function that opens any file like this:

Private Function OpenFile(Byval strFileName as String) as boolean

Dim Y
Y = FreeFile

Open strFileName for Input as Y

'Do whatever
Close Y

End Function

'-or-


Private Function OpenFile(byval strFileName as String) as boolean

Open strFileName for Output as #1
'Do whatever
Close #1
End Function
Reply With Quote
  #3  
Old 12-17-2002, 11:31 AM
Thanatos's Avatar
Thanatos Thanatos is offline
Contributor
 
Join Date: Jul 2002
Location: New Paltz, NY
Posts: 447
Default

actually i mean a file that might currently be in use by another program
__________________
Fir Na Tine
Reply With Quote
  #4  
Old 12-17-2002, 11:49 AM
ALEX_0077's Avatar
ALEX_0077 ALEX_0077 is offline
Contributor
 
Join Date: Nov 2002
Location: American Canyon, CA
Posts: 622
Default

Oh.

In that case, maybe this will help you. its a code at vbDiamond
that was written by Jerry Barnett

Click here to see example stuff on checking to see if file is open or something

PS. Hope this helps.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->