Microsoft Small Basic

Program Listing: QQT667
' Sample program using the TITLE property.
' This one uses TextWindow multiple times to set the title property.
' A second version will use GraphicsWindow.
'
' Purpose: To illustrate the problem of using the TITLE property between the Desktop & Web IDE's.
'
' CAUTION:
' To allow this listing to run in the Web IDE, there are 5 lines that must be removed, commented:
' - 42; 49; 118 : .CursorTop
' - 47 : .Title
' - 151 : .CursorLeft

' Previous version published as http://smallbasic.com/program/?TZT429 with 18! lines to be altered.

' Run the program
Main()

Sub Main
' initialise
Initialise()

task = "INITIAL"
doTask()

task = "ADDITION"
doTask()

task = "SUBTRACTION"
doTask()

task = "MULTIPLICATION"
doTask()

task = "DIVISION"
doTask()

' wait for user to press a key
task = "FINISHED"
doTask()

' position cursor for end text
' TextWindow.CursorTop = l * c
EndSub ' Main

Sub doTask
' comment the following line if using the Small Basic web IDE
' TextWindow.Title = setTitle + task

' TextWindow.CursorTop = l * c

' perform each task
If (task = "INITIAL") Then
foreColour1 = "DarkGray"
foreColour2 = "Gray"
highlight = " |||||| "
EndIf

If (task = "ADDITION") Then
foreColour1 = "DarkGreen"
foreColour2 = "Green"
highlight = " |||||||| "
doTaskTitle()
TextWindow.WriteLine(a + " + " + b + " = " + (a + b) )
EndIf

If (task = "SUBTRACTION") Then
foreColour1 = "DarkRed"
foreColour2 = "Red"
highlight = " ||||||||||| "
doTaskTitle()
TextWindow.WriteLine(a + " - " + b + " = " + (a - b) )
EndIf

If (task = "MULTIPLICATION") Then
foreColour1 = "DarkYellow"
foreColour2 = "Yellow"
highlight = " |||||||||||||"
doTaskTitle()
TextWindow.WriteLine(a + " x " + b + " = " + (a * b) )
EndIf

If (task = "DIVISION") Then
foreColour1 = "DarkMagenta"
foreColour2 = "Magenta"
highlight = " ||||||| "
doTaskTitle()
TextWindow.WriteLine(a + " / " + b + " = " + (a / b) )
EndIf

If (task = "FINISHED") Then
foreColour1 = "Black"
foreColour2 = "White"
highlight = " ||||||| "
EndIf

goHighlight()

' increment task counter
c = c + 1
EndSub ' doTask

Sub doTaskTitle
TextWindow.ForegroundColor = foreColour1
TextWindow.WriteLine(task)
TextWindow.ForegroundColor = "White"
EndSub ' doTaskTitle

Sub goHighlight
' highlight the window Title property change
For i = 1 To delay / d
If Math.Remainder(i,2) = 0 Then
TextWindow.ForegroundColor = foreColour2
Else
TextWindow.ForegroundColor = foreColour1
EndIf
' TextWindow.CursorTop = 0
TextWindow.WriteLine(highlight)
Program.Delay(delay)
EndFor
TextWindow.ForegroundColor = "White"
EndSub ' goHighlight

Sub Initialise
' values for sums
a = 6
b = 3

' line multiplier for each task
c = 0

' divisor for flashing title highlighter
d = 25

' lines per task
l = 3

delay = 250

' set up for changing window title
setTitle = "Small Basic : TextWindow.Title : "
' what we are about to do
task = ""
' title highlighter
highlight = " "

' marker for the end of the highlighter string
TextWindow.Write(" <")
' reset the cursor to the left edge
' TextWindow.CursorLeft = 0
EndSub ' Initialise