Chad Snyder
Chad Snyder

Reputation: 9

Error "Function call on left side of assignment must return Variant or Object"

So here is a code snippet. The error I am getting is "Function call on left side of assignment must return Variant or Object". I changed the function return to a variant data type, but that did not help.

I am trying to generate a random string using function calls. Because it is a large number of sub tables I want to maintain the tables separated like so instead of in a single long series of code for ease of maintainability.

If this is not viable, can anyone suggest an alternative method of doing this?

Private Function GenAstStrategicResouce() As Variant

    Dim X As Integer

    X = Int((200 * Rnd) + 1)

    If X < 10 Then
        GenStrategicResouce = "Bose-Einstein Condensates"
    ElseIf X < 20 Then
        GenStrategicResouce = "Diamonds"
    End If

End Function

Upvotes: 0

Views: 1687

Answers (1)

user4039065
user4039065

Reputation:

Declare the function to return a string.

You also have mistyped the function's name on the return as GenStrategicResouce instead of GenAstStrategicResouce.

Private Function GenAstStrategicResouce() As STRING

    Dim X As long

    X = Int((200 * Rnd) + 1)

    If X < 10 Then
        GenAstStrategicResouce = "Bose-Einstein Condensates"
    ElseIf X < 20 Then
        GenAstStrategicResouce = "Diamonds"
    End If

End Function

It cannot return anything else so a variant (typically used to possibly return a CVErr or array) is unnecessary.

Upvotes: 2

Related Questions