📄 子过程求方阵元素之和.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "例[8-9]求方阵所有元素之和"
ClientHeight = 2280
ClientLeft = 60
ClientTop = 345
ClientWidth = 4725
LinkTopic = "Form1"
ScaleHeight = 2280
ScaleWidth = 4725
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "求和"
Height = 615
Left = 3360
TabIndex = 5
Top = 1440
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "产生方阵"
Height = 615
Left = 3360
TabIndex = 4
Top = 240
Width = 1215
End
Begin VB.TextBox Text1
Height = 1215
Left = 960
MultiLine = -1 'True
TabIndex = 1
Top = 240
Width = 2175
End
Begin VB.Label Label3
BorderStyle = 1 'Fixed Single
Height = 375
Left = 960
TabIndex = 3
Top = 1680
Width = 2175
End
Begin VB.Label Label2
Caption = "元素和:"
Height = 375
Left = 120
TabIndex = 2
Top = 1800
Width = 735
End
Begin VB.Label Label1
Caption = "方阵为:"
Height = 375
Left = 120
TabIndex = 0
Top = 240
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim a() As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer
ReDim a(6, 6)
For i = 1 To 6
For j = 1 To 6
a(i, j) = 89 * Rnd + 10
Text1.Text = Text1.Text & a(i, j) & " "
Next j
Text1.Text = Text1.Text & vbCrLf
Next i
End Sub
Private Sub Command2_Click()
Call suma(a())
End Sub
Private Sub suma(a() As Integer)
Dim i As Integer, j As Integer
Dim sum As Integer
For i = 1 To UBound(a, 1)
For j = 1 To UBound(a, 2)
sum = sum + a(i, j)
Next j
Next i
Label3.Caption = Str(sum)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -