QMBasic  -  Type Conversion

Top  Previous  Next

 

QMBasic variables are of variant type, the stored type being determined by the context in which the value was set and conversion being carried out on a temporary basis wherever necessary to perform processing. For example, the following program fragment

 

A = 962

S = A[2,1]

 

would result in A containing the integer value 962 and S containing the digit 6 as a string. The type conversion from integer to string is implicit in the use of the substring extraction on the second line.

 

Where a variable is accessed a very large number of times, there may be performance benefits to be obtained from ensuring that it is stored in an appropriate type thus minimising implicit temporary conversions. The QMBasic language does not have any specific type conversion functions as the automatic type variant nature of the language is adequate for most purposes. Where a variable is to be forced to be a number, this can be achieved by adding zero

A = A + 0

or, more typically, combined with some other operation such as

NUM.INVOICES = CLI.REC<C.INV.CT> + 0

 

Similarly, data can be forced to string format by appending a null string

A = A : ""

This is a much less common operation in real programs.