以下vb程序帮忙改正

来源:百度知道 编辑:UC知道 时间:2024/06/18 06:56:40
Private Sub Form_Load()
Private Function s(n) As Integer
if n = 1 then s = 1 eise s = s( n - 1 ) + n
End Function

Private Sub commandsum_click()
n = Val(txtn.Text)
If n <= 0 Then
txtsum.text = ”n<0,数据错误”
Else
txtsum.Text = Str(s(n))
ebd sub

Private Sub commandend_click()

End
End Sub
End Sub

如果你确定你的控件名称没有问题的话,代码修改如下:
Private Function s(n) As Integer
If n = 1 Then s = 1 Else s = s(n - 1) + n
End Function

Private Sub commandsum_click()
n = Val(txtn.Text)
If n <= 0 Then
txtsum.Text = "n<0,数据错误"
Else
txtsum.Text = Str(s(n))
End Sub

你的错误有:
1、字符输入错误,例如else输入成eise
2、你不知道标点符号中西文有差异。西文标点是运算符,中文标点是普通字符。
3、vb的过程都是独立的,不能再一个过程中书写一个新过程。但可以调用。你在Form_Load中包含了两个过程:commandend_click、commandsum_click和一个函数s。应该修改如上。
如果你要在窗体装入的时候就运行这些,(前面的不变)可这样写:
Private Sub Form_Load()
commandsum_click
End Sub
但是因为,窗体还没有显示就输出,显示出来后什么痕迹都没有了,必须再加一条:
Private Sub Form_Load()
Me.AutoRedraw = True
commandsum_click
End Sub