2

In my VBA program for excel; I have a function called "ParamCheck" which get four "double" variables, checks them and returns a message as "string".

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

and now I need to call this function in my sub program. Here is the code

Dim checkParam As String    ' result of validity check of parameters
Set checkParam = ParamCheck(speedAir, valueFCU, aboveSea, elevationTerrain)

when running it gives me this error "object required" and highlights "checkParam"

1 Answer 1

11

You don't need the keyword Set for the type String, that's why.

Unlike to other programming languages, VBA considers String as a Data Type, and not as an Object.

The keyword Set is used to assign a reference to an object (Worksheet, Range, etc...).

If you try to assign a reference to a data type, as you did, you will get an error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.