Vb问题 双击窗体,在输入消息框中输入两个数,将其和与差显示在窗体上。 我编程咋不正确呢?
PrivateFunctionprime(x%,y%)AsIntegerDimc%,d%c=x+yd=x-yEndFunctionPrivateSubForm_DblCl...
Private Function prime(x%, y%) As Integer
Dim c%, d%
c = x + y
d = x - y
End Function
Private Sub Form_DblClick()
Dim a%, b%, p%, q%
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b)
q = prime1(a, b)
Print "a+b="; p
Print
Print "a-b="; q
End Sub
我输出老是 a+b=0 a-b=0 哪位老师帮忙指导一下? 展开
Dim c%, d%
c = x + y
d = x - y
End Function
Private Sub Form_DblClick()
Dim a%, b%, p%, q%
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b)
q = prime1(a, b)
Print "a+b="; p
Print "a-b="; q
End Sub
我输出老是 a+b=0 a-b=0 哪位老师帮忙指导一下? 展开
2个回答
展开全部
Private Function prime(x, y) As Integer
Dim c
c = x + y
prime = c
End Function
Private Function prime1(x, y) As Integer
Dim d
d = x - y
prime1 = d
End Function
Private Sub Form_DblClick()
Dim a%, b%, p%, q%
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b)
q = prime1(a, b)
Print "a+b="; p
Print
Print "a-b="; q
End Sub
vb中函数结果一定要赋给函数名否则无法返回
函数中的内部变量不能被外部调用
如果要简单的话干脆这样
Private Sub Form_DblClick()
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
Print "a+b="; a+b
Print
Print "a-b="; a-b
End Sub
Dim c
c = x + y
prime = c
End Function
Private Function prime1(x, y) As Integer
Dim d
d = x - y
prime1 = d
End Function
Private Sub Form_DblClick()
Dim a%, b%, p%, q%
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b)
q = prime1(a, b)
Print "a+b="; p
Print "a-b="; q
End Sub
vb中函数结果一定要赋给函数名否则无法返回
函数中的内部变量不能被外部调用
如果要简单的话干脆这样
Private Sub Form_DblClick()
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
Print "a+b="; a+b
Print "a-b="; a-b
End Sub
展开全部
按照你的要求,你的代码有错误,具体原因为
当你输入ab值后,执行下列语句
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b)
传给
Private Function prime(x%, y%) As Integer
Dim c%, d%
c = x + y
d = x - y
End Function
进行加减运算
结果输出c 与d值
但 是要把c值传给p,还是传给q呢,所以导致都为0,
正确为:
Private Sub Form_DblClick()
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b, 0)
q = prime(a, b, 1)
Print "a+b="; p
Print
Print "a-b="; q
End Sub
Private Function prime(x, y, z) As Integer
If z = 0 Then prime = Val(x) + Val(y)
If z = 1 Then prime = Val(x) - Val(y)
End Function
当你输入ab值后,执行下列语句
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b)
传给
Private Function prime(x%, y%) As Integer
Dim c%, d%
c = x + y
d = x - y
End Function
进行加减运算
结果输出c 与d值
但 是要把c值传给p,还是传给q呢,所以导致都为0,
正确为:
Private Sub Form_DblClick()
a = Val(InputBox("please input the first number:", "data input"))
b = Val(InputBox("please input the second number:", "data input"))
p = prime(a, b, 0)
q = prime(a, b, 1)
Print "a+b="; p
Print "a-b="; q
End Sub
Private Function prime(x, y, z) As Integer
If z = 0 Then prime = Val(x) + Val(y)
If z = 1 Then prime = Val(x) - Val(y)
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |