前端之家收集整理的这篇文章主要介绍了
VB 检测文件变化 并获取变化的数据,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As Long
Dim file_bytes As String
'用于检测文件夹是否存在
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Command2_Click()
Label2(1).Caption = ""
End Sub
Private Sub Form_Load()
Label5.Caption = ALL_PATH
Dim FS,F As String,FL As String
Set FS = CreateObject("Scripting.FileSystemObject")
If FS.FileExists(ALL_PATH) = True Then
Label6.Caption = "Have test data!"
Dim Out As String
Out = "File size: " & FileLen(ALL_PATH) & "bytes"
file_bytes = FileLen(ALL_PATH)
Label7.Caption = Out
Else
Label6.Caption = "No test data!"
End If
Call check_update '檢測是否更新了
End Sub
'根据文件大小变化判断是否变化
Private Function check_update()
Do While file_bytes = FileLen(ALL_PATH)
DoEvents
Loop
file_bytes = FileLen(ALL_PATH)
Call loade_data
End Function
'循环到文件最后并提取数据
Private Function loade_data()
Dim gotline As String
Dim NUM,RESULT As String
Dim ARR
Open ALL_PATH For Input As #4
Do While Not EOF(4)
Line Input #4,gotline
Loop
Close #4
ARR = Split(gotline,";",-1,1)
NUM = ARR(4)
RESULT = ARR(5)
Label2(1).Caption = "CH " & NUM & " " & RESULT
Call check_update
End Function
原文链接:https://www.f2er.com/vb/260515.html