我想要一个函数,其中我可以插入两个整数,结果它会返回一个整数。
Sub test()
Dim x As Integer
x = getConst 1, 0 ' here is where i get the error message
MsgBox "Vakue" & x
End Sub
Function getConst(ry As Integer, rx As Integer) As Integer
getConst = 3 'actually that one: getConst = 34 * ry * ry - 30 * ry + 8.5 * rx * rx + 7.5 * rx, but that should make any difference
End Function我习惯了Java编码,它应该有点像那样工作,但它写的是"Erwartet: Anweisungsende“,所以在英语中,”Expetteteof子句“
发布于 2016-01-06 10:49:45
从函数中检索值需要括号
x = getConst(1, 0)但是,当您将它们作为一个过程调用(而不检索返回值)时,您可以忘记截止符:
getConst 1, 0发布于 2016-01-06 10:53:22
唯一的问题是Sub Test()中函数调用前后缺少括号.即
x = getConst(1, 0)当您在实际函数中乘以小数时,您应该重新考虑使用整数变量。
Sub test()
Dim x As Integer
x = getConst(1, 0)
MsgBox "Value " & x
End Sub
Function getConst(ry As Integer, rx As Integer) As Integer
' getConst = 3 'actually that one:
' getConst = 34 * ry * ry - 30 * ry + 8.5 * rx * rx + 7.5 * rx
' but that should make any difference
getConst = 34 * ry ^ 2 - 30 * ry + 8.5 * rx ^ 2 + 7.5 * rx
End Functionhttps://stackoverflow.com/questions/34631152
复制相似问题