请教用VB的MSFlexGrid控件读取数据的问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 20:45:13
有一个txt格式的数据:(年份;流量)两列,我想把这数据读到MSFlexGrid上,并且将年份保存在Y(n)中,将流量保存在X(n)中,请教一下,代码怎么写?还有读取的数组保存在n中。多谢了,无以答谢,只能给积分了。

代码如下,有不明白的发消息问我。

Private Sub Command1_Click()
Open App.Path + "\data.txt" For Input As #1 '程序路径下的data.txt文件

Dim x(), y() As String
Dim i As Integer
MSFlexGrid1.Cols = 3
MSFlexGrid1.TextMatrix(0, 1) = "年份"
MSFlexGrid1.TextMatrix(0, 2) = "流量"
Do While Not EOF(1)
Line Input #1, tmp
If tmp <> "" Then
arr = Split(tmp, " ") '这里是以空格为分隔的,如果是逗号就用split(str,",")
If UBound(arr) > 0 Then
i = i + 1
ReDim Preserve y(i - 1)
ReDim Preserve x(i - 1)
y(i - 1) = arr(0)
x(i - 1) = arr(1)
MSFlexGrid1.TextMatrix(i, 1) = arr(0)
MSFlexGrid1.TextMatrix(i, 2) = arr(1)
MSFlexGrid1.AddItem ""
End If
End If
Loop
Close #1
End Sub