McBasic™Get McBasic™ ↗
Build 881
Practical guide

Connect an event to complete behavior

Understand the binding, the procedure signature and the state transition behind a working event.

An event has two halves#

A handler needs both a binding and a matching BASIC procedure. A procedure named cmdSave_Click is not sufficient if the control’s event list points somewhere else. Conversely, a binding cannot execute a missing procedure. Select the control, choose the event in the event editor, and confirm the generated signature against the component reference.

Preserve the signature#

Keep parameter types, order and ByRef modifiers exactly as the event contract declares. ByRef parameters can let your handler influence the operation, such as cancelling a close or marking keyboard input handled. Renaming a local parameter is different from changing its type or direction.

Requires mBusy and lblStatus in the owning Form
Private Sub Form_QueryUnload(ByRef Cancel As Integer, ByVal UnloadMode As Integer)
    If mBusy Then
        Cancel = 1
        lblStatus.Caption = "Wait for the current operation to finish."
    End If
End Sub

This guard alone does not implement cancellation. The download lesson includes the complete cancel-and-close sequence.

Choose the event by meaning#

Event familyTypical responsibility
Click / command activationStart a user-requested action.
Change / ValueChangedReact to the new value of a component. Use its actual documented event name.
ShownStart work that needs the visible Form, such as an asynchronous load.
KeyDown / KeyPress / KeyUpHandle physical keys separately from committed text input.
SelectionChangedInspect the new selection and guard the no-selection case.
Completed / FailedFinish or report an asynchronous media operation.
QueryUnload / UnloadDecide whether closure may proceed, then release owned resources.

Not every component offers every event. The reference shows each supported signature and its parameters.

Make state transitions explicit#

A long-running action normally has idle, busy, success and failure states. Reject repeated activation while busy, disable conflicting commands and restore them in Finally. A success label belongs after the operation succeeds, not immediately after starting it. Keep previous valid data visible if a refresh fails.

Avoid accidental loops#

Assigning a property inside its own Change handler may cause another value transition. Normalize only when needed and keep the operation idempotent. Use a clearly scoped update flag when several controls must be updated together, and release it in every exit path. Do not use a timer as a substitute for correctly handling an event.

Source baseline 20f4bfed6b · Build manifest