📄 form4.frm
字号:
VERSION 5.00
Begin VB.Form Form4
BackColor = &H00FFC0C0&
Caption = "矩阵加减"
ClientHeight = 8085
ClientLeft = 60
ClientTop = 345
ClientWidth = 11880
LinkTopic = "Form4"
LockControls = -1 'True
ScaleHeight = 8085
ScaleWidth = 11880
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command7
Caption = "返回首界面"
Height = 500
Left = 6840
TabIndex = 10
Top = 6720
Width = 1360
End
Begin VB.PictureBox Picture4
BackColor = &H00FFC0C0&
Height = 3000
Left = 9000
ScaleHeight = 2940
ScaleWidth = 2925
TabIndex = 9
Top = 1560
Width = 2980
End
Begin VB.CommandButton Command6
Caption = "差为"
Enabled = 0 'False
Height = 500
Left = 9840
TabIndex = 8
Top = 5520
Width = 1360
End
Begin VB.PictureBox Picture3
BackColor = &H00FFC0C0&
Height = 3000
Left = 6000
ScaleHeight = 2940
ScaleWidth = 2940
TabIndex = 7
Top = 1560
Width = 3000
End
Begin VB.PictureBox Picture2
BackColor = &H00FFC0C0&
Height = 3000
Left = 3000
ScaleHeight = 2940
ScaleWidth = 2940
TabIndex = 6
Top = 1560
Width = 3000
End
Begin VB.PictureBox Picture1
BackColor = &H00FFC0C0&
Height = 3000
Left = 0
ScaleHeight = 2940
ScaleWidth = 2925
TabIndex = 5
Top = 1560
Width = 2980
End
Begin VB.CommandButton Command5
Caption = "退出"
Height = 500
Left = 9840
TabIndex = 4
Top = 6720
Width = 1360
End
Begin VB.CommandButton Command4
Caption = "清除再来"
Height = 500
Left = 3840
TabIndex = 3
Top = 6720
Width = 1360
End
Begin VB.CommandButton Command3
Caption = "和为"
Enabled = 0 'False
Height = 500
Left = 6840
TabIndex = 2
Top = 5520
Width = 1360
End
Begin VB.CommandButton Command2
Caption = "输入B"
Enabled = 0 'False
Height = 500
Left = 3840
TabIndex = 1
Top = 5520
Width = 1360
End
Begin VB.CommandButton Command1
Caption = "输入A"
Height = 500
Left = 840
TabIndex = 0
Top = 5520
Width = 1360
End
Begin VB.Label Label4
BackColor = &H00FFC0C0&
Caption = "两矩阵之差"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 405
Left = 9960
TabIndex = 14
Top = 720
Width = 1095
End
Begin VB.Label Label3
BackColor = &H00FFC0C0&
Caption = "两矩阵之和"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 405
Left = 6840
TabIndex = 13
Top = 720
Width = 1095
End
Begin VB.Label Label2
BackColor = &H00FFC0C0&
Caption = "矩阵B"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 405
Left = 3960
TabIndex = 12
Top = 720
Width = 1095
End
Begin VB.Label Label1
BackColor = &H00FFC0C0&
Caption = "矩阵A"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 405
Left = 840
TabIndex = 11
Top = 720
Width = 1095
End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim x() As Single
Dim y() As Single
Dim z() As Single
Dim m As Single
Dim n As Single
Private Sub Command1_Click()
m = Val(InputBox("请输入矩阵A的行数", ""))
If m = Val("") Then
MsgBox "行列不能为零或空,请正确输入行列数" '判断行列输入是否正确
Exit Sub
End If
If m - Int(m) <> 0 Then
MsgBox "行数为整数,请正确输入"
Exit Sub
End If
n = Val(InputBox("请输入矩阵A的列数", ""))
If n = Val("") Then
MsgBox "行列不能为零或空,请正确输入行列数" '判断行列输入是否正确
Exit Sub
End If
If n - Int(n) <> 0 Then
MsgBox "列数为整数,请正确输入"
Exit Sub
End If
If m <= 0 Or n <= 0 Then
MsgBox "行列应该大于零,请重新输入"
Exit Sub
End If
ReDim x(m, n)
For i = 1 To m
For j = 1 To n
x(i, j) = Val(InputBox("输入矩阵x (" & i & "," & j & ") 的值", ""))
Next j
Next i
For i = 1 To m
For j = 1 To n
Picture1.Print Space(2); Format(x(i, j), "0.00"); '输出原矩阵x
Next j
Picture1.Print
Next i
Command1.Enabled = False
Command2.Enabled = True
End Sub
Private Sub Command2_Click()
Dim m1 As Single
Dim n1 As Single
Dim p As Single
m1 = Val(InputBox("请输入矩阵A的行数", ""))
If m1 = Val("") Then
MsgBox "行列不能为零或空,请正确输入行列数" '判断行列输入是否正确
Exit Sub
End If
If m1 - Int(m1) <> 0 Then
MsgBox "行数为整数,请正确输入"
Exit Sub
End If
n1 = Val(InputBox("请输入矩阵A的列数", ""))
If n1 = Val("") Then
MsgBox "行列不能为零或空,请正确输入行列数" '判断行列输入是否正确
Exit Sub
End If
If n1 - Int(n1) <> 0 Then
MsgBox "列数为整数,请正确输入"
Exit Sub
End If
If m <= 0 Or n <= 0 Then
MsgBox "行列应该大于零,请重新输入"
Exit Sub
End If
If m1 <> m Or n1 <> n Then
MsgBox "不符合相加法则请重新输入"
Else
ReDim y(m1, n1)
For i = 1 To m1
For j = 1 To n1
y(i, j) = Val(InputBox("输入矩阵x (" & i & "," & j & ") 的值", ""))
Next j
Next i
For i = 1 To m1
For j = 1 To n1
Picture2.Print Space(2); Format(y(i, j), "0.00"); '输出原矩阵y
Next j
Picture2.Print
Next i
Command2.Enabled = False
End If
Command3.Enabled = True
Command6.Enabled = True
End Sub
Private Sub Command3_Click()
Picture3.Cls
ReDim z(m, n)
For i = 1 To m
For j = 1 To n
z(i, j) = x(i, j) + y(i, j) '把原矩阵x,y相加
Next j
Next i
For i = 1 To m
For j = 1 To n
Picture3.Print Space(2); Format(z(i, j), "0.00"); '输出和矩阵
Next j
Picture3.Print
Next i
Command3.Enabled = False
End Sub
Private Sub Command4_Click()
Picture1.Cls
Picture2.Cls
Picture3.Cls
Picture4.Cls
Command1.Enabled = True
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
Picture4.Cls
ReDim w(m, n)
For i = 1 To m
For j = 1 To n
w(i, j) = x(i, j) - y(i, j) '把原矩阵x,y相减
Next j
Next i
For i = 1 To m
For j = 1 To n
Picture4.Print Space(2); Format(w(i, j), "0.00"); '输出和矩阵
Next j
Picture4.Print
Next i
Command6.Enabled = False
End Sub
Private Sub Command7_Click()
Form4.Hide
Form3.Show
End Sub '返回开始界面
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -