# CallByDispId
{: .no_toc }

Calls a method, or reads or writes a property, on an object --- looked up by raw IDispatch dispatch ID at run time. **CallByDispId** is a twinBASIC addition; the by-name variant, [**CallByName**](/tB/Modules/Interaction/CallByName.md), exists in VBA as well.

Syntax: **CallByDispId(** *object* **,** *dispid* **,** *calltype* [ **,** *args* ... ] **)**

*object*
: *required* **Object**. The object whose member is to be invoked.

*dispid*
: *required* **Long**. The IDispatch dispatch ID (`DISPID`) of the method or property to invoke.

*calltype*
: *required* A [**VbCallType**](/tB/Modules/Constants/VbCallType.md) value indicating the kind of member: `vbMethod`, `vbGet`, `vbLet`, or `vbSet`.

*args*
: *optional* The arguments to pass to the method, **Property Get**, **Property Let**, or **Property Set**.

The return value is a **Variant** containing whatever the call returned. For methods that return nothing, or for property assignments, the result is **Empty**.

**CallByDispId** skips the name lookup that [**CallByName**](/tB/Modules/Interaction/CallByName.md) performs, which is useful in two situations: when the dispatch ID is already known and the cost of a `GetIDsOfNames` round trip should be avoided, and when the target member is not exposed by name (e.g. a default member with `DISPID_VALUE = 0`, an explicit-DISPID extension, or a hidden/restricted member).

### Common Errors

| Error | When |
|---|---|
| [438 (`&H1B6`)](/Reference/Run-time-Errors.md#438), *Object doesn't support this property or method* | *object* has no member with the dispatch ID *dispid* |
| [-2147467259 (`&H80004005`)](/Reference/Run-time-Errors.md#-2147467259), *Unspecified error* | *calltype* is not one of the **VbCallType** values, or *object* is **Nothing** |
| [-2147352562 (`&H8002000E`)](/Reference/Run-time-Errors.md#-2147352562), *Invalid number of parameters.* | the number of *args* is not the number the member takes |
| [94 (`&H5E`)](/Reference/Run-time-Errors.md#94), *Invalid use of Null* | *calltype* is **Null** |

### Example

This example invokes the default member of an object --- `DISPID_VALUE`, defined as 0 --- by dispatch ID.

```tb check_build
Const DISPID_VALUE As Long = 0

Dim SomeObject As Object
Dim Result As Variant
Result = CallByDispId(SomeObject, DISPID_VALUE, vbGet)
```

### See Also

- [CallByName](/tB/Modules/Interaction/CallByName.md) function
- [VbCallType](/tB/Modules/Constants/VbCallType.md) enumeration
