QMBasic - Type Conversion |
|
|
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.
When the national language support decimal separator character is set to something other than the period, both the selected character and the period are recognised as being a valid decimal separator when converting a numeric value in a string to its internal numeric form.. |