Write and call BASIC procedures
Use functions, ByRef parameters and explicitly bounded arrays.
A Function returns a result through its own name. ByRef lets Increment update the caller’s variable, while ByVal gives Sum ordinary value parameters. Array bounds are explicit: this example begins at -2, so code must ask LBound rather than assuming zero or one.
Step 1Prepare a safe practice project#
Extract the archive into a new writable folder, separate from your own application. Open HelloConsole.mcproj in McBasic™. Keep every declared source, layout, resource and migration file together.
To reconstruct it yourself, create a ConsoleApp 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": "b29f7058-01a5-4eca-ac79-5f035e4c3e1c",
"name": "HelloConsole",
"kind": "ConsoleApp",
"language": {
"dialect": "McBasic1",
"requireExplicit": true,
"compare": "Binary",
"defaultArrayBase": 0
},
"forms": [],
"modules": [
{
"name": "Main",
"path": "Main.bas"
}
],
"classes": [],
"tests": [],
"references": [],
"resources": [],
"targets": [
"osx-arm64"
],
"capabilities": []
}Step 2Declare the modules and public contract#
This is a nonvisual ConsoleApp project. Add the declared modules and classes; do not create a dummy Form. Public members are its API and Private members are implementation details.
Step 3Connect the events explicitly#
The entry points are callable procedures, not Designer events. Keep their names and signatures exactly as shown in the code.
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.
Main.bas
Enter these declarations at file scope, before the procedures.
Option ExplicitPublic Function Sum(ByVal left As Long, ByVal right As Long) As Long
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Public Function Sum(ByVal left As Long, ByVal right As Long) As Long
Sum = left + right
End FunctionPublic Sub Increment(ByRef value As Long)
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Public Sub Increment(ByRef value As Long)
value = value + 1
End SubPublic Sub Main()
Enter this helper in the named source file, outside every other procedure. Its callers are included in the same project.
Public Sub Main()
Dim value As Long
Dim values(-2 To 2) As Integer
value = Sum(20, 21)
Call Increment(value)
values(-2) = 7
Debug.Print "McBasic: " & value
Debug.Print values(-2)
Debug.Print LBound(values)
End SubCopy the complete Main.bas file
Replace the file once; do not append duplicate procedures.
Option Explicit
Public Function Sum(ByVal left As Long, ByVal right As Long) As Long
Sum = left + right
End Function
Public Sub Increment(ByRef value As Long)
value = value + 1
End Sub
Public Sub Main()
Dim value As Long
Dim values(-2 To 2) As Integer
value = Sum(20, 21)
Call Increment(value)
values(-2) = 7
Debug.Print "McBasic: " & value
Debug.Print values(-2)
Debug.Print LBound(values)
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 HelloConsole.mcproj
mcbasic run HelloConsole.mcprojAcceptance checklist
- Run and confirm the output includes McBasic™: 42.
- Confirm the element at index -2 prints 7.
- Confirm LBound reports -2.
Step 7Make one change and repeat the tests#
Change the array bounds and use LBound/UBound in a loop that visits every element.
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