# Read
{: .no_toc }

Loads a resource from the compiled executable into the **cRes** instance.

Syntax: *object*.**Read**( *id*, *Type* ) **As cRes**

*id*
: *required* A **Variant** identifying the resource to load. Pass a numeric **Long** to identify the resource by its integer ID, or a **String** to identify it by name.

*Type*
: *required* A **Variant** identifying the resource type. Pass a numeric **Long** for a predefined resource type (for example, `2` for `RT_BITMAP`), or a **String** for a named custom resource type (for example, `"CUSTOM"`).

**Read** calls the **LoadResData** function with the supplied *id* and *Type* arguments and stores the resulting byte array internally. The method returns the **cRes** instance itself, so calls to the retrieval methods ([**ReturnBytes**](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnBytes.md), [**ReturnString**](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnString.md), [**ReturnHex**](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnHex.md), [**ReturnBase64**](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnBase64.md), [**ReturnPicture**](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnPicture.md)) can be chained directly onto the **Read** call.

> [!IMPORTANT] timeless
> **Read** must be called before any retrieval method. The resource data is not populated at construction time; a retrieval method called without a prior **Read** will operate on an empty byte array and may raise a runtime error.

> [!NOTE] 1.0.0.4
> **Read** can load only a resource that is part of the project. *Type* names a folder under **Resources** in the Project Explorer (or is the number of a standard resource type), and *id* identifies a resource in it. If no resource matches, **LoadResData** raises a run-time error.

### Example

This example loads a custom binary resource by name and retrieves it as a byte array, then loads an image resource by integer ID and assigns it to a **PictureBox**.

```tb check_build
Private Sub Form_Load()
    ' Load a named custom resource and retrieve the raw bytes.
    Dim res As New cRes
    res.Read "CONFIG_DATA", "CUSTOM"
    Dim data() As Byte
    data = res.ReturnBytes()

    ' Load an image stored as a PNG resource by integer ID and display it.
    Dim imgRes As New cRes
    Picture1.Picture = imgRes.Read(101, "PNG").ReturnPicture()
End Sub
```

### See Also

- [ReturnBytes](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnBytes.md) method
- [ReturnString](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnString.md) method
- [ReturnHex](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnHex.md) method
- [ReturnBase64](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnBase64.md) method
- [ReturnPicture](/tB/Packages/Contributed/TBMANLIB_RES/cRes/ReturnPicture.md) method
