vb编写一个关于阶乘的程序,
窗体外观如图,程序运行时,在文本框中输入一个整数。如果输入的数据小于、等于0,提示重新输入,如果大于0,计算该整数的阶乘,并显示计算结果。要求用函数计算阶乘。(vb编程方...
窗体外观如图,程序运行时,在文本框中输入一个整数。如果输入的数据小于、等于0,提示重新输入,如果大于0,计算该整数的阶乘,并显示计算结果。要求用函数计算阶乘。(vb编程方法越多越好!很急)
展开
2个回答
展开全部
刚给你写的 希望对你有帮助 给个满意回答吧
Private Sub Command1_Click()
Dim dat1 As Variant
Dim sum As Variant
Dim i As Integer
dat1 = Val(Text1.Text)
sum = 1
If dat1 <= 0 Then
MsgBox "请重新输入", vbExclamation + vbOKOnly, "提示"
Else
For i = 1 To dat1
sum = sum * i
Next i
Text2.Text = CStr(sum)
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Label1.Caption = "输入数据"
Label2.Caption = "阶乘"
Command1.Caption = "计算"
Command2.Caption = "退出"
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command1_Click()
Dim dat1 As Variant
Dim sum As Variant
Dim i As Integer
dat1 = Val(Text1.Text)
sum = 1
If dat1 <= 0 Then
MsgBox "请重新输入", vbExclamation + vbOKOnly, "提示"
Else
For i = 1 To dat1
sum = sum * i
Next i
Text2.Text = CStr(sum)
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Label1.Caption = "输入数据"
Label2.Caption = "阶乘"
Command1.Caption = "计算"
Command2.Caption = "退出"
Text1.Text = ""
Text2.Text = ""
End Sub
追问
高手啊,可是可以,有没有简单的哦,比如说用for循环语句
追答
就是用的for循环啊
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询