McBasic™Get McBasic™ ↗
Build 881
Practical guide

Choose arrays, collections and records

Use the container whose ownership, indexing and mutation model matches your task.

Pick the right shape#

ShapeUse it forIndex / identity
ArrayA typed sequence or multi-dimensional valuesDeclared lower and upper bounds; inspect LBound/UBound.
CollectionAn ordered group of values, optionally keyedOne-based positions or a key.
DictionaryLookup by a stable text keyString keys; inspect Exists before Item.
JsonValueA structured document received or encoded as JSONObject members by name; arrays from zero.
RecordsetRows returned by a database queryRow positions plus column names.
BindingSourceA view used by data-aware controlsLoaded rows; editing a draft is not a SQL write.
TreeNodesA hierarchy of node objectsOne-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.

Source baseline 20f4bfed6b · Build manifest