📄 frmmagic.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMagic
Caption = "魔方矩阵"
ClientHeight = 4365
ClientLeft = 60
ClientTop = 345
ClientWidth = 5370
LinkTopic = "Form1"
ScaleHeight = 4365
ScaleWidth = 5370
StartUpPosition = 3 '窗口缺省
Begin MSComctlLib.ListView ltvMagic
Height = 2655
Left = 600
TabIndex = 3
Top = 1320
Width = 4095
_ExtentX = 7223
_ExtentY = 4683
View = 3
LabelEdit = 1
LabelWrap = -1 'True
HideSelection = -1 'True
GridLines = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.CommandButton cmdCreate
Caption = "创 建"
Height = 375
Left = 3840
TabIndex = 2
Top = 720
Width = 855
End
Begin VB.TextBox txtSize
Height = 375
Left = 600
TabIndex = 0
Top = 720
Width = 3015
End
Begin VB.Label Label1
Caption = "魔方矩阵的大小"
Height = 255
Left = 600
TabIndex = 1
Top = 360
Width = 1575
End
End
Attribute VB_Name = "frmMagic"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Size As Double '保存以前矩阵的大小
Private theMagic As mymagic.Magic 'magic对象的实例
Private Sub Form_Load()
'本函数在装载窗体时被调用
'创建一个新的Magic类实例
On Error GoTo Handle_Error
Set theMagic = New mymagic.Magic
Size = 0
Exit Sub
Handle_Error:
MsgBox (Err.Description)
End Sub
Private Sub cmdCreate_Click()
'本函数在"Create"按钮被按下时被调用
'调用magicdemo方法,并显示魔方
Dim y As Variant
If Size <= 0 Or theMagic Is Nothing Then Exit Sub
On Error GoTo Handle_Error
Call theMagic.magicdemo(1, y, Size)
Call ShowMatrix(y)
Exit Sub
Handle_Error:
MsgBox (Err.Description)
End Sub
Private Sub txtSize_Change()
'本函数在文本框中的内容改变时被调用
'设置Size的当前值
On Error Resume Next
Size = CDbl(txtSize.Text)
If Err <> 0 Then
Size = 0
End If
End Sub
Private Sub ShowMatrix(y As Variant)
'本函数用y的值填充ListView列表框
'假设y包含一个二维数组
Dim n As Long
Dim i As Long
Dim j As Long
Dim nLen As Long
Dim Item As ListItem
On Error GoTo Handle_Error
'获取数组大小
If IsArray(y) Then
n = UBound(y, 1)
Else
n = 1
End If
'设置列标题
nLen = ltvMagic.Width / 5
Call ltvMagic.ListItems.Clear
Call ltvMagic.ColumnHeaders.Clear
Call ltvMagic.ColumnHeaders.Add(, , "", nLen, lvwColumnLeft)
For i = 1 To n
Call ltvMagic.ColumnHeaders.Add(, , _
"Column " & Format(i), nLen, lvwColumnLeft)
Next
'添加数组内容
If IsArray(y) Then
For i = 1 To n
Set Item = ltvMagic.ListItems.Add(, , "Row " & Format(i))
For j = 1 To n
Call Item.ListSubItems.Add(, , Format(y(i, j)))
Next
Next
Else
Set Item = ltvMagic.ListItems.Add(, , "Row 1")
Call Item.ListSubItems.Add(, , Format(y))
End If
Exit Sub
Handle_Error:
MsgBox (Err.Description)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -