实时监控文件夹内TXT文件又遇上麻烦,请版主帮忙
以下是我根据各位版主给的帮助拼写的代码红色为出错部分
Private Sub Timer1_Timer()
Dim k As Integer
Dim TmpStr As String
Dim str1() As String
Dim str2() As String
Dim q As Integer
Dim p As Integer
Dim o As String
Dim r As String
z = File1.ListCount
For p = 0 To z - 1
o = File1.List(p)
Open (File1.Path & "\" & o) For Input As #1
Do While Not EOF(1)
Line Input #1, r
r = Text & r & vbCrLf
Loop
Close #1
TmpStr = r '首先将字符串赋值给一个变量
str1 = Split(TmpStr, ",") '将以,为标记分割后的字符串数组赋值给数组变量str1
With MSFlexGrid1 '下面的四个属性也可以在设计时设定
.Rows = 199
.Cols = 39
.FixedCols = 1
.FixedRows = 1
For k = 0 To UBound(str1) - 1
str2() = Split(str1(k), ":") '将以:为标记分割后的字符串数组赋值给数组变量str2
.TextMatrix(2 * p, k + 1) = Replace(str2(0), "*", "")
.TextMatrix(2 * p + 1, k + 1) = str2(1)
Next
End With
Next p
End Sub
PS。如果不用TIMER计时器就不会有问题,很奇怪!