我的VBA代码看起来像这样:
user enters value for variable
isnumeric(this variable)
user enters value for another variable
isnumeric(this variable now)
user enters value for a third variable
isnumeric(this third variable)
有没有办法用以下内容替换它:
user enters variable
call CheckIfThisIsNumeric
go back to other function and repeat this process several times
所以我不必在我的程序中写一百万次IsNumeric?
如果这是非正式的,请道歉。
答案 0 :(得分:0)
正如我所看到的,唯一的方法是将变量放入全局变量中。一件坏事有两个原因:
不过,你可以做一个
Public myVariableforCheckingNumericity As Variant
(.../...)
myVariableforCheckingNumericity = ThisVariable
If CheckIfThisIsNumeric Then......
Function CheckIfThisIsNumeric () As Boolean
CheckIfThisIsNumeric = IsNumeric(myVariableforCheckingNumericity)
End Function
然而,正如评论者所说,整体利益是消极的。