VB 检测文件变化 并获取变化的数据
来源:互联网 发布:明基th682st知乎 编辑:程序博客网 时间:2024/05/04 11:22
Private Declare Function PathFileExists Lib "shlwapi.dll" Alias "PathFileExistsA" (ByVal pszPath As String) As LongDim file_bytes As String'用于检测文件夹是否存在
Private Sub Command1_Click()Unload MeEnd SubPrivate Sub Command2_Click()Label2(1).Caption = ""End SubPrivate Sub Form_Load()Label5.Caption = ALL_PATHDim FS, F As String, FL As StringSet 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 = OutElse Label6.Caption = "No test data!"End IfCall check_update '檢測是否更新了End Sub
'根据文件大小变化判断是否变化Private Function check_update() Do While file_bytes = FileLen(ALL_PATH) DoEvents Loop file_bytes = FileLen(ALL_PATH) Call loade_dataEnd Function
'循环到文件最后并提取数据Private Function loade_data()Dim gotline As StringDim NUM, RESULT As StringDim ARROpen ALL_PATH For Input As #4 Do While Not EOF(4) Line Input #4, gotline Loop Close #4ARR = Split(gotline, ";", -1, 1)NUM = ARR(4)RESULT = ARR(5)Label2(1).Caption = "CH " & NUM & " " & RESULTCall check_updateEnd Function