用VB求1到n的和,n自己填 50
展开全部
Private Function PlusUntilN() As Long
Dim a As Long, b As Long, i As Long
a = Val(InputBox("请输入 N 值:", "赋值", "100"))
If a <= 0 Then
MsgBox "请正确输入数值!", vbExclamation + vbOKOnly, "提示"
Exit Function
End If
b = 0
For i = 1 To a
b = b + i
Next i
PlusUntilN = b
End Function
调用:MsgBox PlusUntilN()
望采纳。。。
Dim a As Long, b As Long, i As Long
a = Val(InputBox("请输入 N 值:", "赋值", "100"))
If a <= 0 Then
MsgBox "请正确输入数值!", vbExclamation + vbOKOnly, "提示"
Exit Function
End If
b = 0
For i = 1 To a
b = b + i
Next i
PlusUntilN = b
End Function
调用:MsgBox PlusUntilN()
望采纳。。。
追问
这是VB吗
追答
是VB啊。。。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询