📄 随机生成数组并求其中的最大,小值.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3075
ClientLeft = 60
ClientTop = 465
ClientWidth = 4920
LinkTopic = "Form1"
ScaleHeight = 3075
ScaleWidth = 4920
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "生成数组求最大值和最小值"
Height = 615
Left = 2640
TabIndex = 5
Top = 2160
Width = 1695
End
Begin VB.TextBox Text2
Height = 375
Left = 3600
TabIndex = 4
Top = 1320
Width = 855
End
Begin VB.TextBox Text1
Height = 375
Left = 1080
TabIndex = 2
Top = 1320
Width = 855
End
Begin VB.PictureBox Picture1
Height = 375
Left = 360
ScaleHeight = 315
ScaleWidth = 4035
TabIndex = 0
Top = 240
Width = 4095
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "最小值"
Height = 180
Left = 2640
TabIndex = 3
Top = 1320
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "最大值"
Height = 180
Left = 360
TabIndex = 1
Top = 1320
Width = 540
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Base 1
Private Sub Command1_Click()
Dim a(10) As Integer, i As Integer, amax As Integer, amin As Integer
'生成数组
Randomize
For i = 1 To 10
a(i) = Int(90 * Rnd) + 10 'int((upperbound - lowerbound + 1) * rnd + lowerbound)
Picture1.Print a(i);
Next i
'求最大值,最小值
amax = a(1): amin = a(1)
For i = 1 To 10
If a(i) > amax Then amax = a(i) '求最大值
If a(i) < amin Then amin = a(i) '求最小值
Next i
Text1.Text = CStr(amax)
Text2.Text = CStr(amin)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -