Validate a customer-entry Form
Keep user input, validation feedback and the save action in agreement.
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
{
"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 property | Value |
|---|---|
Caption | "Customer entry" |
Height | 320 |
Width | 640 |
| Type | Name | Parent |
|---|---|---|
| TextBox | txtName | Form |
| Label | lblStatus | Form |
| CommandButton | cmdSave | Form |
| CheckBox | chkReadOnly | Form |
txtName · exact Inspector values
| Property | Value |
|---|---|
Enabled | True |
Height | 32 |
Left | 24 |
MultiLine | False |
ReadOnly | False |
TabIndex | 0 |
Text | "New customer" |
Top | 32 |
Visible | True |
Width | 520 |
WordWrap | False |
| Anchor edges | Left, Top |
lblStatus · exact Inspector values
| Property | Value |
|---|---|
Caption | "Replace the sample name, then save." |
Enabled | True |
Height | 56 |
Left | 24 |
TabIndex | 1 |
Top | 88 |
Visible | True |
Width | 560 |
| Anchor edges | Left, Top |
cmdSave · exact Inspector values
| Property | Value |
|---|---|
Caption | "Save customer" |
Enabled | True |
Height | 32 |
Left | 24 |
TabIndex | 1 |
Top | 176 |
Visible | True |
Width | 160 |
| Anchor edges | Left, Top |
chkReadOnly · exact Inspector values
| Property | Value |
|---|---|
Caption | "Read-only name" |
Checked | False |
Enabled | True |
Height | 32 |
Left | 216 |
TabIndex | 2 |
Top | 180 |
Visible | True |
Width | 280 |
| Anchor edges | Left, Top |
Step 3Connect the events explicitly#
frmMain
| Object | Event | Procedure | Parameters |
|---|---|---|---|
txtName | Change | txtName_Change | Change() |
cmdSave | Click | cmdSave_Click | Click() |
chkReadOnly | Change | chkReadOnly_Change | Change() |
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.
Option ExplicitPrivate Sub chkReadOnly_Change()
Read the current value or selection and update its dependent interface. The binding above determines which object calls this handler.
Private Sub chkReadOnly_Change()
txtName.ReadOnly = chkReadOnly.Checked
End SubPrivate Sub txtName_Change()
Read the current value or selection and update its dependent interface. The binding above determines which object calls this handler.
Private Sub txtName_Change()
lblStatus.Caption = "Ready to save."
End SubPrivate Sub cmdSave_Click()
Enter the complete action, including its input checks and calls to helper procedures.
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 SubCopy the complete Forms/frmMain.bas file
Replace the file once; do not append duplicate procedures.
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 SubStep 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:
mcbasic check CustomerEntry.mcproj
mcbasic run CustomerEntry.mcprojAcceptance 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.
20f4bfed6b · Build manifest