VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Checks whether a file exists at a location before trying to open it (traps file errors)

by Rob Hendricks (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 25th July 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Checks whether a file exists at a location before trying to open it (traps file errors)

API Declarations


'# Created By Rob Hendricks - IBM Corporation#
'# Created on 25/07/01 #


Rate Checks whether a file exists at a location before trying to open it (traps file errors)



'declares the location variable
location = "C:\readme.txt"
'sets the location variable to the readme.txt file on c:If Dir$(location) <> "" Then
'checks whether the readme file exists, if dir$ returns anything other than "" then the file exists
Open location For Input As #1
'opens the file to be put into a text box inthe next line
Text1 = Input(LOF(1), #1)
'puts the whole contents ofthe file into the tex1 textbox
Close #1
'closes the file again
Else
MsgBox "File not found at this location, Please Check the Path", , "File Not found"
'displays an error message if the file doesnt exist
End If

Download this snippet    Add to My Saved Code

Checks whether a file exists at a location before trying to open it (traps file errors) Comments

No comments have been posted about Checks whether a file exists at a location before trying to open it (traps file errors). Why not be the first to post a comment about Checks whether a file exists at a location before trying to open it (traps file errors).

Post your comment

Subject:
Message:
0/1000 characters