Method

# Operator_Lookup

<div class="rst-class">

forsearch

</div>

Operator

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Allows the overloading of a class's lookup operator.

## Notes

Use <span class="title-ref">Operator_Lookup</span> to define a function that will be called if the called item cannot otherwise be found in the class.

Operator_Lookup overloads a class's lookup operator. The method's first parameter must be a `String</api/data_types/string>` which will receive the name of the desired member. The method can have any combination of other parameters and can have any return type. The <span class="title-ref">Operator_Lookup</span> operator is called whenever you use the object.member syntax to look up a member of an object and the compiler can't find anything named "bar". Before it returns an Undefined Identifier error, the compiler will try to call a lookup operator and pass "bar" as the first parameter. Overloading works for the lookup operator just as it does for any other method.

<div class="warning">

<div class="title">

Warning

</div>

If you implement <span class="title-ref">Operator_Lookup</span> on a class, you will no longer get compilation errors if you, for example, inadvertently misspell a property name. Instead, the <span class="title-ref">Operator_Lookup</span> method is called at runtime and is passed the name of your incorrectly spelled property.

</div>

## Sample code

Gets values entered as dot notation from a Dictionary and returns the value:

``` xojo
' Gets values entered as dot notation from a dictionary
' MyClass.AnyName returns what is in
' ValueDict.Value("AnyName")

Function Operator_Lookup(name As String) As String
  If ValueDict.HasKey(name) Then
    Return ValueDict.Value(name)
  Else
    Return ""
  End If
End Function
```

This code defines "SquareLength" in the Vector class (see `Operator Add</api/language/operators/operator_overloads/operator_add>`), a class with two `integer</api/data_types/integer>` properties, x and y.

``` xojo
Function Operator_Lookup(Name As String) As Double
  If Name = "SquareLength" Then Return Self.x^2 + Self.y^2
End Function
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When you write:

``` xojo
Var myDouble As Double
myDouble = myVector.SquareLength
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

it will return the result of the calculation. However, you can also write:

``` xojo
myDouble = myVector.UndefinedFunction ' does not exist
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Operator Overloading</api/language/operators/operator_overloads/operator_overloading>`

</div>
