VBA代码编写,在窗体的文本框TextBox1中输入不大于9的整数,然后计算其阶 ...
发布网友
发布时间:2024-09-15 09:58
我来回答
共1个回答
热心网友
时间:2024-09-25 18:58
Private Sub CommandButton1_Click()
Dim a, b1, b2, i, tmp
Set b1 = Me.TextBox1
Set b2 = Me.TextBox2
a = b1.Text
If Len(a) = 0 Then tmp = "#Len = 0": GoTo 1000
If Not IsNumeric(a) Then tmp = "#Not Is Number": GoTo 1000
a = a * 1
If Int(a) <> a Then tmp = "#not Integer": GoTo 1000
If a < 1 Or a > 9 Then tmp = "#" & IIf(a < 1, "<1", ">9"): GoTo 1000
tmp = a
For i = a - 1 To 2 Step -1
tmp = tmp * i
Next
1000:
b2.Text = tmp
End Sub