VB编程从文件夹中提取数据以矩阵的形式显示出来
在考生文件夹中创建一个工程文件execise9_3.vbp及窗体文件execise9_3.frm。文件夹中的名为in9.txt的文件内容为:132,423,36,58,5...
在考生文件夹中创建一个工程文件execise9_3.vbp及窗体文件execise9_3.frm。文件夹中的名为in9.txt的文件内容为:132,423,36,58,58,16,98,545,314,42,52,24,73,26,9,12,26,375,4,57,60,72,80,51,327。要求:运行程序后,单击窗体,把文件in9.txt中的数据输入到二维数组Mat中,在窗体上按5行、5列的矩阵形式显示出来,然后交换矩阵第一行和第二行的数据,并在窗体上输出交换后的矩阵。
展开
1个回答
2013-08-29
展开全部
Dim mat(4, 4) As Integer
Private Sub Form_Click()
Me.Cls
a = FreeFile
Open App.Path & "\in9.txt" For Input As #a
Line Input #a, b
m = Split(b, ",")
Close #a
For i = 0 To 4
For j = 0 To 4
mat(i, j) = m(i * 4 + j)
Print mat(i, j),
Next j
Print
Next i
Print "交换后的结果"
For j = 0 To 4
t = mat(1, j)
mat(1, j) = mat(0, j)
mat(0, j) = t
Next j
For i = 0 To 4
For j = 0 To 4
Print mat(i, j),
Next j
Print
Next i
End Sub
Private Sub Form_Click()
Me.Cls
a = FreeFile
Open App.Path & "\in9.txt" For Input As #a
Line Input #a, b
m = Split(b, ",")
Close #a
For i = 0 To 4
For j = 0 To 4
mat(i, j) = m(i * 4 + j)
Print mat(i, j),
Next j
Next i
Print "交换后的结果"
For j = 0 To 4
t = mat(1, j)
mat(1, j) = mat(0, j)
mat(0, j) = t
Next j
For i = 0 To 4
For j = 0 To 4
Print mat(i, j),
Next j
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询