Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What VB Function Is The Equivalent To VFP's File() Function ? 1

Status
Not open for further replies.

drosenkranz

Programmer
Sep 13, 2000
360
US
Hello,

I wanted to know if anyone here knew what the VB function was that is equivalent to VFP's File() function when you're checking to see if a file exists in a user's directory.

Thanks The 2nd mouse gets the cheese.
 
Try this little bit of code. I use this in one of my VB applications. I am still looking for another code byte for you. I use the VB getAttr Function which is a member of the file system object or known as (fso)

' Check if file exists without disturbing Dir() function
' If file does not exist, but folder with same name does, return False
' If drive not ready, file exists and is corrupted, or network unavailable, return false
Public Function FileExists(pstrFile As String) As Boolean
On Error GoTo FileExistsErr

FileExists = True
If GetAttr(pstrFile) And vbDirectory Then FileExists = False

FileExistsExit:
Exit Function
 
I dont think there is an equivalent in the VB language itself. Most implementations I've seen to do this involve either:

1. As Claytech's example above, trap for an error when attempting to access the file:

iFN = FreeFile
On Error Resume Next
Open "C:\myfile.txt" For Input Access Read Shared As #iFN
If Err.Number = 0 Then
MsgBox "It's there!"
Close #iFN
End If

2. Use the FileSystemObject:

Set oFSO = CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists("C:\myfile.txt") Then MsgBox "It's there!"
Jon Hawkins
 
Thanks jonscott8 and everyone else,

I'm checking the user's version of files (FileTimeDate()) and then killing the user's version and copying the server's version to the user's machine. Have lost the file on several occasion for unknown reasons. This is happening about twice a month to someone (randomly to 1 out of 90 users). I resorted to using On Error statements and rechecking that the file actually exists after the copy procedure.

I'm pretty sure that's where they lose the file but I don't know WHY they lose it.

Thanks again for the logic and code snips everyone.

Dave The 2nd mouse gets the cheese.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top