Object Versus Numeric Variables
Rule
The suffix of a variable name decides its kind: $ is a string,
! is an object, no suffix is a number, and % is an integer.
DECLARE takes a type and a variable name ending in !, one
variable per statement: DECLARE BBjString x!, never
DECLARE String x$, and DECLARE BBjNumber a!, b! does not
compile either.
A and A% are numeric variables, not objects, so A.toString() or A%.toString() fails (A.toString() passes a syntax-only check); BBjNumber and BBjInt methods need an object variable (name ends in !).
Why
Methods exist only on objects. A numeric variable holds a plain number, so there is
nothing to call a method on; copying the number into a variable whose name ends in
! gives an object whose methods (toString(),
intValue(), ...) can be called.
Edge
A ! variable accepts any value: a number, a string or an object, and it
may hold a number now and text later (x! = 3 followed by
x! = "text" compiles). Never suggest that a ! variable is the
wrong choice for a value because of the value's type; the rule above is about calling
methods on a variable that is not an object.
A%.toString() fails even the plain compile, while
A.toString() passes bbjcpl -N and fails only the type check
(bbjcpl -t), as the rule says. For a PRO/5-style answer use a function:
STR(A) gives A as a string.
Evidence
DECLARE Verb -- the type and the variable a declaration takes.
BBjNumber -- "To access BBjNumber methods, copy a BBj numeric value to an object variable."
Types in BBj -- the suffixes
and the ! object suffix.
Compiler result (BBj 26.03): bbjcpl -N rejects
DECLARE String x$, DECLARE BBjNumber var1!, var2! and
A%.toString(), and accepts DECLARE BBjString x!,
DECLARE BBjNumber n!, A.toString() (which the type check
rejects) and the example below.
Example
A numeric variable and its object copy:
A = 12.5 PRINT STR(A) x! = A PRINT x!.toString()
A declared BBjNumber variable, and a ! variable that held a
number and now holds text:
rem 'a ! variable is an object and accepts any value declare BBjNumber n! n! = 12.5 x! = 3 x! = "now text" print n!.toString(), x!