在我的用于excel的VBA程序中,我有一个名为"ParamCheck“的函数,它获取四个”双精度“变量,检查它们并以”字符串“的形式返回一条消息。
Function ParamCheck(airSpeed As Double, FCUvalue As Double, _
altitude As Double, terrainElevation As Double) As String
If airSpeed < MIN_CONTROL_SPEED Then
'check if airspeed is less than 119 ft/min or not
ParamCheck = "Airspeed is less than minimum control speed"
ElseIf FCUvalue > FCU_VALUE_LIMIT Then
'check if FCU value if greater than 10 or not
ParamCheck = "FCU value is greater than limit"
ElseIf FCUvalue < 0 Then
'check if FCU vlaue is negative or not
ParamCheck = "FCU value is negative"
ElseIf altitude <= terrainElevation Then
'check if altitude is greater that terrain of elevation or not
ParamCheck = "Altitude is less than terrain elevation"
Else
'if all the parameters are valid print a "Valid" message
ParamCheck = PARAMS_OK
End If
End Function现在我需要在我的子程序中调用这个函数。以下是代码
Dim checkParam As String ' result of validity check of parameters
Set checkParam = ParamCheck(speedAir, valueFCU, aboveSea, elevationTerrain)当运行它时,我看到这个错误"object required“并突出显示了"checkParam”
发布于 2013-05-07 15:09:33
类型字符串不需要关键字Set,这就是原因所在。
与其他编程语言不同,VBA将String视为数据类型,而不是对象。
关键字Set用于将引用分配给对象(工作表、范围等)。
如果您尝试将引用分配给数据类型,则会得到一个错误。
https://stackoverflow.com/questions/16413159
复制相似问题