vb编程题目求具体解答过程
1、窗体界面由1个标签、1个图片框、3个文本框和4个命令按钮组成,请参照参考界面完成所有对象的属性设置;
2、单击"生成数组"按钮,在图片框中显示5行5列的数组;
3、单击"列和"和"行和"按钮,分别在对应的文本框中显示数组的行和与列和;
4、单击"对角线和"按钮,计算数组主对角线和副对角线元素之和并显示在文本框 展开
Option Base 1
Dim intArray(5, 5) As Integer
Private Sub Command1_Click()
Randomize
Dim i As Integer, j As Integer
Me.Picture1.Cls
For i = 0 To 2
Me.Text1(i).Text = ""
Next i
For i = 1 To 5
For j = 1 To 5
intArray(i, j) = Int(Rnd(i * j) * 9 + 1)
Me.Picture1.Print intArray(i, j);
Next j
Me.Picture1.Print
Next i
End Sub
Private Sub Command2_Click(Index As Integer)
Dim i As Integer, j As Integer, intRowSum(5) As Integer, intColumnSum(5) As Integer, intDiagonalSum(2) As Integer
Select Case Index
Case 0
For i = 1 To 5
For j = 1 To 5
intRowSum(i) = intRowSum(i) + intArray(i, j)
If j Mod 5 = 1 Then
Me.Text1(Index).Text = Me.Text1(Index).Text & CStr(intArray(i, j))
Else
Me.Text1(Index).Text = Me.Text1(Index).Text & "+" & CStr(intArray(i, j))
End If
Next j
Me.Text1(Index).Text = Me.Text1(Index).Text + "=" + CStr(intRowSum(i))
Me.Text1(Index).Text = Me.Text1(Index) + vbCrLf
Next i
Case 1
For j = 1 To 5
For i = 1 To 5
intColumnSum(j) = intColumnSum(j) + intArray(i, j)
If i Mod 5 = 1 Then
Me.Text1(Index).Text = Me.Text1(Index).Text & CStr(intArray(i, j))
Else
Me.Text1(Index).Text = Me.Text1(Index).Text & "+" & CStr(intArray(i, j))
End If
Next i
Me.Text1(Index).Text = Me.Text1(Index).Text + "=" + CStr(intColumnSum(j))
Me.Text1(Index).Text = Me.Text1(Index) + vbCrLf
Next j
Case 2
For i = 1 To 5
intDiagonalSum(1) = intDiagonalSum(1) + intArray(i, i)
If i Mod 5 = 1 Then
Me.Text1(Index).Text = Me.Text1(Index).Text + CStr(intArray(i, i))
Else
Me.Text1(Index).Text = Me.Text1(Index).Text + "+" + CStr(intArray(i, i))
End If
Next i
Me.Text1(Index).Text = Me.Text1(Index).Text + "=" + CStr(intDiagonalSum(1))
Me.Text1(Index).Text = Me.Text1(Index).Text + vbCrLf
For i = 1 To 5
intDiagonalSum(2) = intDiagonalSum(2) + CStr(intArray(i, 6 - i))
If i Mod 5 = 1 Then
Me.Text1(Index).Text = Me.Text1(Index).Text + CStr(intArray(i, 6 - i))
Else
Me.Text1(Index).Text = Me.Text1(Index).Text + "+" + CStr(intArray(i, 6 - i))
End If
Next i
Me.Text1(Index).Text = Me.Text1(Index).Text + "=" + CStr(intDiagonalSum(2))
End Select
End Sub