vb利用循环结构编程计算表达式1+1/2+1/3+.....+1/n的值
2,文本框可显示但不可编辑
3,命令按钮command1显示内容为“计算”,格式宋体,加粗,二号字
4,按“计算”按钮,调用inputbox函数输入n,计算表达式,按钮caption属性改为“显示
5,按“显示”按钮,在text1中显示计算结果,按钮caption属性在改为“计算”,可重复执行“计算”操作 展开
Private Sub Command1_Click()
Static n As Long, valSum As Double
Select Case Command1.Caption
Case "计算"
valSum = 0
Dim i As Long
n = InputBox("Pleace input integer n:", "InputBox", 10)
Command1.Caption = "显示"
For i = 1 To n
valSum = valSum + 1 / i
Next i
Case "显示"
Label1.Caption = "n=" + CStr(n)
Text1.Text = valSum
Command1.Caption = "计算"
End Select
End Sub
Private Sub Form_Load()
Text1.Enabled = False
Text1.Text = ""
Command1.Caption = "计算"
Command1.FontBold = True
Command1.FontSize = 22
Command1.FontName = "宋体"
Text1.FontName = "Times New Roman"
Text1.FontBold = True
Text1.FontSize = 22
End Sub