Small Basic - TextWindow Cursor Positioning

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.