Choose arrays, collections and records
Use the container whose ownership, indexing and mutation model matches your task.
Pick the right shape#
| Shape | Use it for | Index / identity |
|---|---|---|
| Array | A typed sequence or multi-dimensional values | Declared lower and upper bounds; inspect LBound/UBound. |
| Collection | An ordered group of values, optionally keyed | One-based positions or a key. |
| Dictionary | Lookup by a stable text key | String keys; inspect Exists before Item. |
| JsonValue | A structured document received or encoded as JSON | Object members by name; arrays from zero. |
| Recordset | Rows returned by a database query | Row positions plus column names. |
| BindingSource | A view used by data-aware controls | Loaded rows; editing a draft is not a SQL write. |
| TreeNodes | A hierarchy of node objects | One-based Items; each node owns its child Nodes. |
Respect bounds and ownership#
An array declared with -2 To 2 has five elements but does not start at zero. ReDim changes dynamic array storage; Preserve has specific shape restrictions. Do not resize an array while another operation depends on its borrowed storage. The language workbench uses explicit bounds so this behavior is visible.
Use keys for identity#
A visible row position changes when a list is filtered or sorted. A stable key survives those presentation changes. A dictionary is useful for in-memory lookup; a database primary key is the identity for persisted records. Use the key, not the current displayed index, when performing an update.
Do not confuse a draft with persistence#
BeginEdit, Delete and CancelEdit on a BindingSource can demonstrate a reversible in-memory edit. They do not make the matching database transaction happen automatically. The choice-binding lab deliberately deletes a row from a draft, then restores it without changing SQLite.
Keep hierarchy explicit#
A TreeNode has its own Nodes and optional Parent. For lazy expansion, preserve the request identity when supplying children; a delayed answer must not populate whichever node happens to occupy the same visible position later. See the complete TreeView lab.
20f4bfed6b · Build manifest