VB中如何将文本中的矩阵数据以数据表格的形式在程序界面读出来
name voltage_L voltage_H sig_type error
CAMFALL -12 12 PULSE 0.100000
CAMRISE 0 5 PULSE 0.200000
VS 0 5 PULSE 0.300000
CRK 0 5 PULSE 0.400000
MAP 0 5 ANALOG 0.500000
每个数据之间是以TAB隔开的
数据:
name voltage_L voltage_H sig_type error
CAMFALL -12 12 PULSE 0.100000
CAMRISE 0 5 PULSE 0.200000
VS 0 5 PULSE 0.300000
CRK 0 5 PULSE 0.400000
MAP 0 5 ANALOG 0.500000 展开
先引用部件MSFlexgrid,CommandDialog
Private Sub Command1_Click()
Dim aTmp As String
Dim iRow As Integer
With cdlOpen
.DialogTitle = "选择txt文件"
.Filter = "(*.txt)|*.txt"
.ShowOpen
If Len(.FileName) = 0 Then Exit Sub
Text1.Text = .FileName
End With
With MSFlexGrid1
.Clear
.Cols = 5
.Rows = 0
End With
Open Text1.Text For Input As #1
Do While Not EOF(1)
Line Input #1, aTmp
Dim vTmp As Variant
Do
If InStr(aTmp, " ") < 1 Then Exit Do
aTmp = Replace(aTmp, " ", " ")
Loop
vTmp = Split(aTmp, " ")
'Text3.Text = Text3.Text & vbCrLf & aTmp
With MSFlexGrid1
'.TextMatrix(iRow, 0) = vTmp(0)
'.TextMatrix(iRow, 1) = vTmp(1)
'.TextMatrix(iRow, 2) = vTmp(2)
'.TextMatrix(iRow, 3) = vTmp(3)
'.TextMatrix(iRow, 4) = vTmp(4)
.AddItem vTmp(0) & Chr(9) & vTmp(1) & Chr(9) & vTmp(2) & Chr(9) & vTmp(3) & Chr(9) & vTmp(4)
'iRow = iRow + 1
End With
Loop
MSFlexGrid1.FixedRows = 1
Close #1
End Sub
运行结果见附图