⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form2.frm

📁 实现矩阵一般功能运算,矩阵相加,减,相乘等功能
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form2 
   BackColor       =   &H00FFC0C0&
   Caption         =   "矩阵转置"
   ClientHeight    =   8085
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   11880
   FillColor       =   &H00FFC0C0&
   LinkTopic       =   "Form2"
   LockControls    =   -1  'True
   ScaleHeight     =   8085
   ScaleWidth      =   11880
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command5 
      Caption         =   "运算"
      Enabled         =   0   'False
      Height          =   660
      Left            =   5040
      TabIndex        =   8
      Top             =   5520
      Width           =   1800
   End
   Begin VB.CommandButton Command4 
      Caption         =   "清除再来"
      Height          =   660
      Left            =   8640
      TabIndex        =   7
      Top             =   5520
      Width           =   1800
   End
   Begin VB.PictureBox Picture2 
      BackColor       =   &H00FFC0C0&
      ForeColor       =   &H00000000&
      Height          =   3500
      Left            =   6240
      ScaleHeight     =   3435
      ScaleWidth      =   4935
      TabIndex        =   4
      Top             =   1080
      Width           =   5000
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H00FFC0C0&
      ForeColor       =   &H00000000&
      Height          =   3500
      Left            =   480
      ScaleHeight     =   3435
      ScaleWidth      =   4935
      TabIndex        =   3
      Top             =   1080
      Width           =   5000
   End
   Begin VB.CommandButton Command3 
      Caption         =   "退出"
      Height          =   660
      Left            =   8640
      TabIndex        =   2
      Top             =   6720
      Width           =   1800
   End
   Begin VB.CommandButton Command2 
      Caption         =   "返回首界面"
      Height          =   660
      Left            =   5040
      TabIndex        =   1
      Top             =   6720
      Width           =   1800
   End
   Begin VB.CommandButton Command1 
      Caption         =   "输入矩阵"
      Height          =   660
      Left            =   1560
      TabIndex        =   0
      Top             =   5520
      Width           =   1800
   End
   Begin VB.Label Label2 
      BackColor       =   &H00FFC0C0&
      Caption         =   "转置矩阵"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   18
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   585
      Left            =   8040
      TabIndex        =   6
      Top             =   360
      Width           =   1755
   End
   Begin VB.Label Label1 
      BackColor       =   &H00FFC0C0&
      Caption         =   "原矩阵"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   18
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   585
      Left            =   2160
      TabIndex        =   5
      Top             =   360
      Width           =   1635
   End
End
Attribute VB_Name = "Form2"
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
 Dim p As Single
 
 
Private Sub Command1_Click()
  Picture1.Cls
  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");  '输出原矩阵
   Next j
   Picture1.Print
  Next i
 Command1.Enabled = False
 Command5.Enabled = True
End Sub

Private Sub Command2_Click()
 Form3.Show
 Form2.Hide                                              '返回开始界面
 Command1.Enabled = True
End Sub

Private Sub Command3_Click()
 End
End Sub

Private Sub Command4_Click()
 Picture1.Cls
 Picture2.Cls                                         ' 清空图片框
 Command1.Enabled = True
 Command5.Enabled = True
End Sub
Private Sub Command5_Click()
 Picture2.Cls
 ReDim b(n, m) As Single
 For j = 1 To n
  For i = 1 To m
   b(j, i) = x(i, j)                                '把原矩阵转置
  Next i
 Next j
 For j = 1 To n
  For i = 1 To m
  Picture2.Print Space(2); Format(b(j, i), "0.00");   '输出转置矩阵
  Next i
  Picture2.Print
 Next j
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -