2

在我的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)

运行时它给我这个错误“需要对象”并突出显示“checkParam”

4

1 回答 1

10

您不需要SetString 类型的关键字,这就是原因。

与其他编程语言不同,VBA 将String视为Data Type,而不是Object

关键字Set用于分配对对象(工作表、范围等)的引用。

如果您尝试将引用分配给数据类型,就像您所做的那样,您将收到错误消息。

于 2013-05-07T07:09:33.470 回答