Reference
Patterns
The idiomatic D3 / PickBASIC boilerplate you write every day - 9 ready-to-paste snippets, each verified against the reference. Copy one, then tweak the names.
File I/O
Open a file
Attach a file to a variable before reading or writing it.
OPEN "","CUSTOMER" TO CUST.F ELSE STOP 201, "CUSTOMER" END
Read an item
Load an item into a dynamic array, handling "not on file".
READ REC FROM CUST.F, ID THEN NAME = REC<1> END ELSE NAME = "" END
Uses read
Locking
Read with a lock, update, release
Update an item safely under concurrency. WRITE (or RELEASE) frees the lock.
READU REC FROM CUST.F, ID LOCKED PRINT "Locked by another process" STOP END THEN REC<3> = BALANCE WRITE REC ON CUST.F, ID ;* WRITE releases the update lock END ELSE RELEASE CUST.F, ID END
Select lists
Dynamic arrays
Read and replace fields
Pull or set values inside a dynamic array by attribute, value, and subvalue.
NAME = REC<1> ;* attribute 1 CITY = REC<5,2> ;* attribute 5, value 2 REC<3> = "ACTIVE" ;* replace attribute 3 REC = REPLACE(REC, 4, 2, 0, "NEW")
Loop over multivalues
Walk each value in a multivalued attribute.
COUNT = DCOUNT(REC<4>, @VM) FOR I = 1 TO COUNT PRINT REC<4,I> NEXT I
Dates
Transactions
Atomic multi-file update
Commit changes to several files as one unit, or roll them all back.
BEGIN WORK WRITE ORD ON ORDERS, OID WRITE LINE ON ORDLINES, LID COMMIT WORK ELSE ROLLBACK WORK STOP "Order not saved" END
Snippets use placeholder names (CUST.F, REC, ID). Swap them for yours. Want a page explained? Paste any of these into the Code Annotator to link every statement and function.