用一个Timer去定时Check:Public Function FileExists(FileName As String) As Boolean' test to see if a file existsConst INVALID_HANDLE_VALUE = -1&
FileExists = Not (GetFileAttributesW(StrPtr(FileName)) = INVALID_HANDLE_VALUE)
End Function
加个timer控件: Private Sub Form_Load() Timer1.Interval = 30000 Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() '检测文件是否存在 End Sub
原來的code是 Public Function gint_CheckIfFileExists(str_AbsolutePath As String) As Integer'Return Value: 1 ボ郎 ' : 0 ボ合盒硈絬タ盽, 郎ぃ ' : -1 ボ合盒硈絬ア毖 Dim str_FileName As String Dim str_PathVolume As String Dim str_ErrorDescription As String On Error GoTo Error_Handler
str_FileName = Dir(str_AbsolutePath, vbDirectory)
If Left(str_AbsolutePath, 2) <> "\\" Then str_PathVolume = gstr_GetStringBeforeStringFromLeft(str_AbsolutePath, "\") ElseIf Left(str_AbsolutePath, 2) = "\\" Then str_PathVolume = gstr_GetStringBeforeStringFromRight(str_AbsolutePath, "\") End If
If str_FileName <> "" Then gint_CheckIfFileExists = 1 Else
str_FileName = Dir(str_PathVolume, vbDirectory)
If str_FileName <> "" Then gint_CheckIfFileExists = 0 Else gint_CheckIfFileExists = -1 End If
End If
Exit Function 我要加呢,請指示.我要把TIMER控件加到哪裡
Private Sub Timer1_Timer() '检测文件是否存在 End Sub里面部分怎么写.之前有检查文件的FUNCTION 我怎么调用. 调用完成后我还要返回结果,是不也应该是个function而不是sub 请指示
dim extRtn& Private Sub Timer1_Timer() '检测文件是否存在 extRtn=gint_CheckIfFileExists(文件名)select case extRtn case 1 '找到处理 '... case 0 '未找到处理 '... case -1 '-1处理 '... end select End Sub
我運行提示Timer variable not defind 是怎麼回事 是沒定義嗎?我該咋定義
Private Sub Form_Load() Timer1.Interval = 30000 Timer1.Enabled = True End Sub 是這樣加嗎 可是我運行不行
FileExists = Not (GetFileAttributesW(StrPtr(FileName)) = INVALID_HANDLE_VALUE)
End Function
Private Sub Form_Load()
Timer1.Interval = 30000
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
'检测文件是否存在
End Sub
Public Function gint_CheckIfFileExists(str_AbsolutePath As String) As Integer'Return Value: 1 ボ郎
' : 0 ボ合盒硈絬タ盽, 郎ぃ
' : -1 ボ合盒硈絬ア毖 Dim str_FileName As String
Dim str_PathVolume As String
Dim str_ErrorDescription As String On Error GoTo Error_Handler
str_FileName = Dir(str_AbsolutePath, vbDirectory)
If Left(str_AbsolutePath, 2) <> "\\" Then
str_PathVolume = gstr_GetStringBeforeStringFromLeft(str_AbsolutePath, "\")
ElseIf Left(str_AbsolutePath, 2) = "\\" Then
str_PathVolume = gstr_GetStringBeforeStringFromRight(str_AbsolutePath, "\")
End If
If str_FileName <> "" Then
gint_CheckIfFileExists = 1
Else
str_FileName = Dir(str_PathVolume, vbDirectory)
If str_FileName <> "" Then
gint_CheckIfFileExists = 0
Else
gint_CheckIfFileExists = -1
End If
End If
Exit Function
我要加呢,請指示.我要把TIMER控件加到哪裡
'检测文件是否存在
End Sub里面部分怎么写.之前有检查文件的FUNCTION 我怎么调用. 调用完成后我还要返回结果,是不也应该是个function而不是sub 请指示
Private Sub Timer1_Timer()
'检测文件是否存在
extRtn=gint_CheckIfFileExists(文件名)select case extRtn
case 1 '找到处理
'...
case 0 '未找到处理
'...
case -1 '-1处理
'...
end select
End Sub
我運行提示Timer variable not defind 是怎麼回事 是沒定義嗎?我該咋定義
Timer1.Interval = 30000
Timer1.Enabled = True
End Sub
是這樣加嗎 可是我運行不行