我在Ms Access中创建了一个函数,调用到窗体中的子过程,但是返回0。 这是函数中的代码:
Public Function Sum(a, b) As Double
Dim total
total = a + b
End Function
窗体中子过程的代码是:
Private Sub cmdDisplay_Click()
Dim a As Double
Dim b As Double
a = Val(Text0)
b = Val(Text2)
MsgBox (Sum(a, b))
End Sub
每次我测试应该将 a 和 b 一起添加的按钮时,它都显示 0。请帮忙
最佳答案
要返回一个值,您必须将其分配给函数名称,其行为就像键入函数返回类型的局部变量;
Public Function Sum(a, b) As Double
Dim total
total = a + b
Sum = total '//sum is the function name and a variable of type double
End Function
或更好(如果你真的需要求和函数):
Public Function Sum(a as double, b as double) As Double
Sum = a + b
End Function
关于ms-access - 函数在 Ms Access 中返回 0 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6438356/