External Links

Creative Science Centre

 

Code Snippets

Tables

Returns the position in a table that the value is or -1 if the value is not in the table. The tbale needs to have the size as the first element (excluding the first element). See example TB1.

constant TB1 {8,2400,9600,14400,28800,19200,38400,57600,115200}

// *****************************************************************************
// returns position in given table or -1 TABLE MUST HAVE SIZE AS ELEMENT 0
// *****************************************************************************

function table.position(*table(),value)
dim j, found = -1
    for j = 1 to table(0)
        if value = table(j) then
            found = j
            break
        endif
    next
    return found
endf

Array

There is currently no array initialiser and so this is used prior to some libraries for example:

constant DATA {1,2,3,4,5,6}
dim data_ary(6)
array.copy(*DATA(),*data_ary(),6)

// *****************************************************************************
// copies a constant into an array as currently there is no array initialiser
// *****************************************************************************
function array.copy(*const(),*array(),size)
dim j
    for j = 0 to size-1
        array(j) = const(j)
    next
endf

String

// *****************************************************************************
// trims leading and trailing non printables and space from front and
// back of a string
// *****************************************************************************
function trim$(line$[80])
dim j, rv$[90]=""
    // trim front
    for j = 0 to strlen(line$)
        if asc(line$,j) > 32 then
            break
        endif
    next
    rv$ = mid$(line$,j,200)
    // trim back
    for j = strlen(rv$) to 0 step -1
        if asc(rv$,j) > 32 then
            break
        endif
    next
    rv$ = mid$(rv$,0,j+1)
    return rv$
endf