Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB 6 Checking if a file on the network exists takes too long

The following code:

    If FileExists(XCustPath + "XCust.dat") Then
        XCustRun
    End If

and this code:

Public Function FileExists(ByVal Fname As String) As Boolean

Dim lRetVal As Long
Dim OfSt As OFSTRUCT

lRetVal = OpenFile(Fname, OfSt, OF_EXIST)
If lRetVal <> HFILE_ERROR Then
    FileExists = True
Else
    FileExists = False
End If

End Function

XCustPath points to a mapped network location with the file XCust.dat inside it.

But on the line:

lRetVal = OpenFile(Fname, OfSt, OF_EXIST)

It takes forever and locks up my program for 20-30 seconds. It needs to check if this file exists on the network in less than 1 second as it is for a legacy point of sale application. Is there anyway I can force it to timeout the line of code if it takes longer than a second? If it does exist it runs smoothly and perfect. Or a VERY quick way of checking if a file on the network exists?

like image 862
daltoncoder Avatar asked Sep 11 '25 08:09

daltoncoder


1 Answers

This should be faster:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.fileexists(Fname) ...
like image 157
xpda Avatar answered Sep 13 '25 08:09

xpda