Small Basic - TextWindow Cursor Positioning

We can write to the TextWindow using Write and WriteLine; the WriteLine variant also adds a 'new line' to position the cursor at the start of the next line.

There are 2 other TextWindow properties that can be used to control where the text is written, these are CursorLeft and CursorTop.  Using these we can get or set the position of the cursor.

There are 80 columns in the TextWindow and the CursorLeft property starts at column 0, with a maximum value of 79 (the last or 80th column).  CursorTop is also indexed from 0.

We can use these properties for several types of applications.  The simplest is probably just to align columns of data as shown below.

For `` i `` = `` 1 `` To ``20

  ``TextWindow``.`` CursorTop `` = ``i``-``1

  `` For `` j `` = `` 1 `` To ``5

    ``TextWindow``.`` CursorLeft `` = ``(``j``-``1``)``*``80``/``5

    ``TextWindow``.``Write``(``"Row "``+``i``)

    ``TextWindow``.`` CursorLeft `` = ``(``j``-``1``)``*``80``/``5``+``8

    ``TextWindow``.``Write``(``"Col "``+``j``)

  ``EndFor

EndFor

TextWindow``.``WriteLine``(``""``)

 

Before windows, many applications used a DOS window (just like a TextWIndow) as an interface.  This can be achieved by careful use of the CursorLeft and CursorTop properties to reposition the cursor as the user interacts. 

This kind of interface is often still used for commercial data entry applications like airline booking screens etc. since they are very robust, and can be very efficient to operate without a mouse.

While ``(``Text``.``ConvertToLowerCase``(``accept`` ) ``<`` > ``"y"``)

  ``NameForm``(``)

EndWhile

TextWindow``.``Clear``(``)

TextWindow``.``WriteLine``(``firstName``+``" "``+``lastName``+``" is "``+``age``)

 

Sub ``NameForm

  ``TextWindow``.``Clear``(``)

  ``TextWindow``.`` CursorLeft `` = ``35

  ``TextWindow``.`` CursorTop `` = ``0

  ``TextWindow``.``Write``(``"NAME FORM"``)

  ``TextWindow``.`` CursorLeft `` = ``0

  ``TextWindow``.`` CursorTop `` = ``2

  ``TextWindow``.``Write``(``"FIRST NAME"``)

  ``TextWindow``.`` CursorLeft `` = ``0

  ``TextWindow``.`` CursorTop `` = ``4

  ``TextWindow``.``Write``(``"LAST NAME"``)

  ``TextWindow``.`` CursorLeft `` = ``0

  ``TextWindow``.`` CursorTop `` = ``6

  ``TextWindow``.``Write``(``"AGE"``)

  ``TextWindow``.`` CursorLeft `` = ``40

  ``TextWindow``.`` CursorTop `` = ``6

  ``TextWindow``.``Write``(``"ACCEPT (Y)"``)

  

  ``TextWindow``.`` CursorLeft `` = ``15

  ``TextWindow``.`` CursorTop `` = ``2

  `` firstName `` = ``TextWindow``.``Read``(``)

  ``TextWindow``.`` CursorLeft `` = ``15

  ``TextWindow``.`` CursorTop `` = ``4

  `` lastName `` = ``TextWindow``.``Read``(``)

  ``TextWindow``.`` CursorLeft `` = ``15

  ``TextWindow``.`` CursorTop `` = ``6

  `` age `` = ``TextWindow``.``ReadNumber``(``)

  ``TextWindow``.`` CursorLeft `` = ``55

  ``TextWindow``.`` CursorTop `` = ``6

  `` accept `` = ``TextWindow``.``Read``(``)

EndSub