用vb语言编写:用函数过程求二维数组各元素之和。的程序
2。打印在图形框中
3.用函数过程求数组周边元素之和并显示在文本框中,数组作为传递的参数。 展开
Private Sub Command1_Click()
'执行按钮
Dim Arr(1 To 6, 1 To 6) As Integer
Call CreatArray(Arr())
Call PrintArray(Arr())
Call CountArr(Arr())
End Sub
Sub CreatArray(RndArr() As Integer)
'生成数组
Dim i, j As Integer
For i = 1 To 6
For j = 1 To 6
RndArr(i, j) = Int(Rnd * 101) + 100
Next j
Next i
End Sub
Sub PrintArray(MyArr() As Integer)
'在图形框中输出数组
Dim i As Integer
Picture1.Cls
'清除原先输出数据
For i = 1 To 6
Picture1.Print Str(MyArr(i, 1)), Str(MyArr(i, 2)), Str(MyArr(i, 3)), Str(MyArr(i, 4)), Str(MyArr(i, 5)), Str(MyArr(i, 6)) & Chr(13)
'输出一行数据后换行再输出下一行
Next i
End Sub
Sub CountArr(MyArr() As Integer)
'求和
Dim i, j As Integer
Dim sum As Integer
sum = 0
For i = 1 To 6
For j = 1 To 6
If (((i = 1) Or (j = 1)) Or ((i = 6) Or (j = 6)) Or ((i = 1) Or (j = 6)) Or ((i = 6) Or (j = 1))) Then
'判断是否是周围元素
sum = sum + MyArr(i, j)
End If
Next j
Next i
Text1.Text = sum
'在文本框输出计算结果
End Sub