McBasic™Get McBasic™ ↗
Build 881
Hands-on tutorial · Input & events

Validate a customer-entry Form

Keep user input, validation feedback and the save action in agreement.

1 Form / control designs1 complete BASIC filesGuided sample project

The Change event responds to edits; Click represents the explicit save request. Do not treat a caption saying “saved” as persistent storage. This lesson is the input boundary: the SQLite labs add the storage boundary. ReadOnly and Enabled serve different purposes; a read-only field remains useful for selection and copying.

Step 1Prepare a safe practice project#

Extract the archive into a new writable folder, separate from your own application. Open CustomerEntry.mcproj in McBasic™. Keep every declared source, layout, resource and migration file together.

To reconstruct it yourself, create a DesktopApp project and add the files declared below. In the complete project, follow these steps as a guided rebuild: replace each named source file once and Check after all its procedures are present.

Exact project configuration
CustomerEntry.mcproj
{
  "schemaVersion": 1,
  "projectId": "378297fa-ce11-4a34-9cd4-327c1477d1d0",
  "name": "CustomerEntry",
  "kind": "DesktopApp",
  "language": {
    "dialect": "McBasic1",
    "requireExplicit": true,
    "compare": "Binary",
    "defaultArrayBase": 0
  },
  "application": {
    "bundleIdentifier": "com.mcbasic.customerentry",
    "version": "0.1.0",
    "buildNumber": "1",
    "startupFormId": "form-main",
    "shutdownMode": "OnStartupFormClosed"
  },
  "forms": [
    {
      "id": "form-main",
      "typeName": "frmMain",
      "layout": "Forms/frmMain.form.json",
      "code": "Forms/frmMain.bas"
    }
  ],
  "modules": [],
  "classes": [],
  "tests": [],
  "references": [],
  "resources": [],
  "targets": [
    "osx-arm64"
  ],
  "capabilities": []
}

Step 2Build the Form and set its properties#

frmMain

Select the Form first and set its properties. Add containers before their children. These are initial Designer values, not statements to paste into a procedure.

Form propertyValue
Caption"Customer entry"
Height320
Width640
TypeNameParent
TextBoxtxtNameForm
LabellblStatusForm
CommandButtoncmdSaveForm
CheckBoxchkReadOnlyForm
txtName · exact Inspector values
PropertyValue
EnabledTrue
Height32
Left24
MultiLineFalse
ReadOnlyFalse
TabIndex0
Text"New customer"
Top32
VisibleTrue
Width520
WordWrapFalse
Anchor edgesLeft, Top
lblStatus · exact Inspector values
PropertyValue
Caption"Replace the sample name, then save."
EnabledTrue
Height56
Left24
TabIndex1
Top88
VisibleTrue
Width560
Anchor edgesLeft, Top
cmdSave · exact Inspector values
PropertyValue
Caption"Save customer"
EnabledTrue
Height32
Left24
TabIndex1
Top176
VisibleTrue
Width160
Anchor edgesLeft, Top
chkReadOnly · exact Inspector values
PropertyValue
Caption"Read-only name"
CheckedFalse
EnabledTrue
Height32
Left216
TabIndex2
Top180
VisibleTrue
Width280
Anchor edgesLeft, Top

Step 3Connect the events explicitly#

frmMain

ObjectEventProcedureParameters
txtNameChangetxtName_ChangeChange()
cmdSaveClickcmdSave_ClickClick()
chkReadOnlyChangechkReadOnly_ChangeChange()

Step 4Enter the complete behavior#

Open the named source file. Enter declarations first, then every procedure. Expand a procedure for its full body, or copy the complete file. Helpers are required: do not stop after entering the first Click handler.

Forms/frmMain.bas

Enter these declarations at file scope, before the procedures.

Forms/frmMain.bas · declarations
Option Explicit
Private Sub chkReadOnly_Change()

Read the current value or selection and update its dependent interface. The binding above determines which object calls this handler.

Forms/frmMain.bas · chkReadOnly_Change
Private Sub chkReadOnly_Change()
    txtName.ReadOnly = chkReadOnly.Checked
End Sub
Private Sub txtName_Change()

Read the current value or selection and update its dependent interface. The binding above determines which object calls this handler.

Forms/frmMain.bas · txtName_Change
Private Sub txtName_Change()
    lblStatus.Caption = "Ready to save."
End Sub
Private Sub cmdSave_Click()

Enter the complete action, including its input checks and calls to helper procedures.

Forms/frmMain.bas · cmdSave_Click
Private Sub cmdSave_Click()
    If Trim(txtName.Text) = "" Then
        lblStatus.Caption = "Enter a customer name."
        txtName.SetFocus
        txtName.SelectAll
        Exit Sub
    End If
    If txtName.Text = "New customer" Then
        lblStatus.Caption = "Replace the sample name."
        Call txtName.SetFocus()
        Call txtName.SelectAll()
        Exit Sub
    End If
    lblStatus.Caption = "Saved " & Trim(txtName.Text)
End Sub
Copy the complete Forms/frmMain.bas file

Replace the file once; do not append duplicate procedures.

Forms/frmMain.bas
Option Explicit

Private Sub chkReadOnly_Change()
    txtName.ReadOnly = chkReadOnly.Checked
End Sub

Private Sub txtName_Change()
    lblStatus.Caption = "Ready to save."
End Sub

Private Sub cmdSave_Click()
    If Trim(txtName.Text) = "" Then
        lblStatus.Caption = "Enter a customer name."
        txtName.SetFocus
        txtName.SelectAll
        Exit Sub
    End If
    If txtName.Text = "New customer" Then
        lblStatus.Caption = "Replace the sample name."
        Call txtName.SetFocus()
        Call txtName.SelectAll()
        Exit Sub
    End If
    lblStatus.Caption = "Saved " & Trim(txtName.Text)
End Sub

Step 5Keep resources and storage reproducible#

No external resource or migration files are declared. Any inline migration, seed data or local JSON is present in the code above. Runtime application data and private preferences are not included in the archive.

Step 6Check, run and test the result#

Save all files and run Check. Resolve diagnostics before Run. Developer CLI users can work from the extracted folder:

Developer CLI
mcbasic check CustomerEntry.mcproj
mcbasic run CustomerEntry.mcproj

Acceptance checklist

  • Type and clear the customer name; observe the feedback.
  • Toggle the read-only option and attempt to edit again.
  • Use Tab to reach the save action without a mouse.

Step 7Make one change and repeat the tests#

Add a second required field and keep its validation message separate from the name field.

Save a working Git checkpoint first. Change one behavior, Check again and repeat the acceptance checklist. Compare with the downloaded solution if a regression appears.

Source baseline 20f4bfed6b · Build manifest