|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Vb6 to check if a text file is already openedI need to determine if a text file is already opened or not. Per the below KB article i wrote a method but it does not work for a text file. It works for an excel file though (thats what the KB says of course :-)). http://support.microsoft.com/kb/213383Public Function CheckIfFileIsOpen(strFileName As String) As Boolean On Error GoTo ErrPoint Dim lngFileNum As Long, lngErrNum As Long lngErrNum = 0 lngFileNum = FreeFile Open strFileName For Input Lock Read As #lngFileNum If lngErrNum = 70 Then CheckIfFileIsOpen = True Exit Function End If Close #lngFileNum CheckIfFileIsOpen = False Exit Function ErrPoint: If Err.Number = 70 Then lngErrNum = Err.Number Resume Next End If End Function I need to determine if a text file is already open using VB6. Any help in this regard is highly appreciated. Cheers, Pradeep
Show quote
Hide quote
"Pradeep" <Prad***@discussions.microsoft.com> wrote in message You won't be able to write anything that will be 100% reliable with text news:ECD54F1A-9168-4AD3-A94E-8BFEB60CF95C@microsoft.com... > Hello, > > I need to determine if a text file is already opened or not. > > Per the below KB article i wrote a method but it does not work for a text > file. It works for an excel file though (thats what the KB says of course > :-)). > > http://support.microsoft.com/kb/213383 > > Public Function CheckIfFileIsOpen(strFileName As String) As Boolean > On Error GoTo ErrPoint > > Dim lngFileNum As Long, lngErrNum As Long > > lngErrNum = 0 > > lngFileNum = FreeFile > > Open strFileName For Input Lock Read As #lngFileNum > > If lngErrNum = 70 Then > CheckIfFileIsOpen = True > Exit Function > End If > > Close #lngFileNum > > CheckIfFileIsOpen = False > > Exit Function > ErrPoint: > If Err.Number = 70 Then > lngErrNum = Err.Number > Resume Next > End If > End Function > > I need to determine if a text file is already open using VB6. > > Any help in this regard is highly appreciated. files. The reason is that many applications, when opening text files, simply read the file into memory and then close it. So, technically, the file's not open even though you might be working with it. Notepad is like this. -- Mike Microsoft MVP Visual Basic "MikeD" <nob***@nowhere.edu> wrote in message Notepad is holding "something", try this; create a folder, make a text file news:%23UMHlp3THHA.600@TK2MSFTNGP05.phx.gbl... > You won't be able to write anything that will be 100% reliable with text > files. The reason is that many applications, when opening text files, > simply read the file into memory and then close it. So, technically, the > file's not open even though you might be working with it. Notepad is like > this. > > -- > Mike > Microsoft MVP Visual Basic in the folder, open it with Notepad. While Notepad is open you can delete the file with no problem, but you cannot delete the folder until you close Notepad. Important? No Interesting? No Don't know why I bothered, but there you are :-) Dave O. Hello Dave,
I am sorry about the delay in responding. Your suggestion has worked. Thanks a lot. Also, sincere thanks to everyone who bothered to drop a suggestion. Cheers, Pradeep
Stop loading data process
Application crashing - trying to track down the problem. Data Type String VB6 App Deployment in Vista Convert decimal to fraction string Autologon on Vista Looking for an easy way to achive this problem. VB6 User Control next problem email attachments? Read/Write permission (earn your quarter, Karl!) |
|||||||||||||||||||||||