请教用VB的MSFlexGrid控件读取数据的问题
有一个txt格式的数据:(年份;流量)两列,我想把这数据读到MSFlexGrid上,并且将年份保存在Y(n)中,将流量保存在X(n)中,请教一下,代码怎么写?还有读取的数...
有一个txt格式的数据:(年份;流量)两列,我想把这数据读到MSFlexGrid上,并且将年份保存在Y(n)中,将流量保存在X(n)中,请教一下,代码怎么写?还有读取的数组保存在n中。多谢了,无以答谢,只能给积分了。
展开
1个回答
展开全部
代码如下,有不明白的发消息问我。
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询