📄 form4.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Factors"
ClientHeight = 3690
ClientLeft = 45
ClientTop = 330
ClientWidth = 4650
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3690
ScaleWidth = 4650
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text1
Height = 285
Left = 120
TabIndex = 3
Text = "Primes"
Top = 2520
Width = 4455
End
Begin VB.CommandButton Command2
Caption = "Exit"
Height = 615
Left = 2400
TabIndex = 2
Top = 2880
Width = 2175
End
Begin VB.CommandButton Command1
Caption = "Calculate"
Height = 615
Left = 120
TabIndex = 1
Top = 2880
Width = 2175
End
Begin VB.ListBox List1
Height = 2205
Left = 120
TabIndex = 0
Top = 120
Width = 4455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Command1.Caption = "Recalculate"
List1.Clear
For l = 1 To 10
List1.AddItem ""
Next
List1.AddItem " 2 = (prime)"
n = 1
z = 2
Do
y = DoEvents() ' releases time slice
z = z + 1
p = z
f = 0
S$ = Str$(p) + " = "
' factor test number
For l = 2 To p
Do
If p / l = p \ l Then
p = p / l
If l < z Then
If f = 0 Then
S$ = S$ + Str$(l)
Else
S$ = S$ + " * " + Str$(l)
End If
End If
f = f + 1
Else
Exit Do
End If
Loop
' check no factors and divisor
' greater than square of test number
If f = 0 And l > Int(Sqr(p)) Then
f = 1
Exit For
End If
' check test number completely divided
If p = 1 Then
Exit For
End If
Next
' check only one factor (itself)
If f = 1 Then
S$ = S$ + " (prime)"
n = n + 1
Text1.Text = "Prime numbers:" + Str$(n)
End If
' scrolls & adds last calculation
List1.RemoveItem 0
List1.AddItem S$
Loop
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Beep
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -