VB编程题
1、编写代码,当用户单击窗体时,由输入对话框输入整数n,并计算 1+1/2!+1/3!+……+1/n!的值,并将运算结果输出到窗体。
2、创建一个登录界面,默认用户名和密码是:“admin : admin”,如果登录尝试超过三次,则自动关闭系统。
1、编写代码,当用户单击窗体时,由输入对话框输入整数n,并计算 1+1/2!+1/3!+……+1/n!的值,并将运算结果输出到窗体。
2、创建一个登录界面,默认用户名和密码是:“admin : admin”,如果登录尝试超过三次,则自动关闭系统。
答案:第一题:Private Sub Form_Click()
Dim n As Integer, i As Integer, j As Integer
Dim sum As Double, s As Double
n = InputBox("输入")
For i = 1 To n
s = 1
For j = 1 To i
s = s * i
Next j
sum = sum + 1 / s
Next i
MsgBox sum
End Sub第二题:
Private Sub Command1_Click()
Static x
If x = 3 Then
MsgBox "有3次了!"
End
End If
If Text1.Text = "admin" And Text2.Text = "admin" Then
MsgBox "进入!"
Else
x = x + 1
End If
End Sub用户:text1 密码:text2
1的答案
Private Sub Command1_Click()
For i = 1 To 10
k = 1
For x = 1 To i
k = k * x
Next
s = s + 1 / k
Next
Print s
End Sub2的答案
Dim a As Integer
Private Sub Command1_Click()
a = a + 1
If Text1.Text = "123" And Text2.Text = "123" Then
MsgBox "密码正确"
ElseIf a = 4 Then
MsgBox "登陆次数达上限."
Unload Me
Else
MsgBox "密码错误"
End If
End Sub