txt读取数据问题
本帖最后由 bcrun 于 2012-02-29 21:40:14 编辑
Private Sub Command1_Click()
Text1(0).MultiLine = True
Text1(1).MultiLine = True
Text1(2).MultiLine = True
End Sub
Public Sub CmdRead_Click()
Dim MDate() As String
Dim MTime() As String
Dim Data1() As String
Dim StrArray() As String
Dim i As Long
i = 0
Open "D:\123.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextString ' 读入一行数据并将其赋予某变量。
StrArray = Split(TextString, " ")
ReDim Preserve MDate(i), MTime(i), Data1(i)
MDate(i) = Mid(StrArray(0), 2)
MTime(i) = StrArray(1)
Data1(i) = Val(StrArray(2))
i = i + 1
Loop
Close #1 ' 关闭文件。
Text1(0).Text = Join(MDate)
Text1(1).Text = Join(MTime)
Text1(2).Text = Join(Data1)
End Sub
Public Sub CmdRead_Click()
Dim MDate() As String
Dim MTime() As String
Dim MyDate() As Date
Dim Data1() As String
Dim StrArray() As String
Dim i As Long
i = 0
Open "D:\123.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextString ' 读入一行数据并将其赋予某变量。
StrArray = Split(TextString, " ")
ReDim Preserve MDate(i), MTime(i), Data1(i), MyDate(i)
MDate(i) = Mid(StrArray(0), 2)
MTime(i) = StrArray(1)
MyDate(i) = Mid(MDate(i), 1, 4) & "-" & Mid(MDate(i), 5, 2) & "-" & Mid(MDate(i), 7, 2) & _
" " & Mid(MTime(i), 1, 2) & ":" & Mid(MTime(i), 3, 2) & ":" & Mid(MTime(i), 5, 2)
Data1(i) = Left(StrArray(2), Len(StrArray(2)) - 1)
Text1(0).Text = Text1(0).Text & MDate(i) & vbCrLf
Text1(1).Text = Text1(1).Text & MTime(i) & vbCrLf
Text1(2).Text = Text1(2).Text & Data1(i) & vbCrLf
Text1(3).Text = Text1(3).Text & MyDate(i) & vbCrLf
i = i + 1
Loop
Close #1 ' 关闭文件。
End Sub
Private Sub Form_Load()
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
End Sub
补充:VB , 基础类