VB 6检查网络上的文件是否存在太长时间 [英] VB 6 Checking if a file on the network exists takes too long

查看:165
本文介绍了VB 6检查网络上的文件是否存在太长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码:

 如果FileExists(XCustPath +XCust.dat)然后
XCustRun
结束如果

和这段代码:

< pre $ public function FileExists(ByVal Fname As String)As Boolean

Dim lRetVal As Long
Dim OfSt As OFSTRUCT

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

End Function

XCustPath指向映射的网络位置,其中包含文件XCust.dat。



行:

  lRetVal = OpenFile(Fname,OfSt,OF_EXIST)

它需要永久的锁定我的程序20-30秒。它需要检查这个文件是否存在于网络上的时间不到1秒,因为这是传统的销售点应用程序。有反正我可以强制它超时的代码行,如果它需要超过一秒?如果它确实存在,它会顺利和完美地运行。或者一个非常快速的方式来检查网络上的文件是否存在?

解决方案

这应该会更快:

b
$ b

  Dim fso As Object 
设置fso = CreateObject(Scripting.FileSystemObject)
if fso.fileexists(Fname)。 ..


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?

解决方案

This should be faster:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.fileexists(Fname) ...

这篇关于VB 6检查网络上的文件是否存在太长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆