|
-
Apr 22nd, 2001, 08:18 PM
#1
Thread Starter
New Member
My program needs to extract Data from a text file, how can I check that the file "C:\Myfile.txt" exists using a control button click before running the rest of the Procedure within the control.
If the File exists ( I want to continue with the procedure )
If not ( I wish to end the Procedure and show a different Form - telling the user the file does not exist etc. )
Can you please help.
-
Apr 22nd, 2001, 08:21 PM
#2
Code:
Private Sub Command1_Click()
If Len(Dir$("C:\myfile.txt"))=0 Then
MsgBox "File Doesn't Exist!"
Exit Sub
End If
'Otherwise
Open "C:\myfile.txt" For Input As #1
'do your work...
Close #1
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 22nd, 2001, 08:21 PM
#3
Hyperactive Member
Example.
Dim objFS as Object
Dim blnExits as boolean
Set objFS = CreatObject("Scripting.FileSystemObject")
blnExist = objFS.FileExists(strPath)
-
Apr 22nd, 2001, 08:28 PM
#4
Thread Starter
New Member
Check "FileExists" before continue with procedure.
Thankyou very Much - Cheers
-
Apr 22nd, 2001, 08:32 PM
#5
Originally posted by John Yingling
Example.
Dim objFS as Object
Dim blnExits as boolean
Set objFS = CreatObject("Scripting.FileSystemObject")
blnExist = objFS.FileExists(strPath)
You should use what VB has or API before considering to use an Object. That code will take a bit longer than what crptcblade has posted since it has to create the FSO object and all .
VB is a first resort.
API is a second.
If all else fails, FSO may be a final resort.
But FSO is just an easier way of programming, I believe.
Everything that is done in FSO can be done with API.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|