Microsoft Small Basic

Program Listing: QLJ036
' TextWindow Colors v0.1
' Copyright (c) 2014 Nonki Takahashi. All rights reserved.
'
' History:
' v0.1 2014-02-24 Created.
'
TextWindow.WriteLine("TextWindow Colors v0.1")
TextWindow.WriteLine("")
Init()
setBC = "True"
' [1] set background color without window clear
ShowColors()
bgColor = "Black"
setBC = "False"
' [2] set background color with window clear
While "True"
GetOpositeColor()
TextWindow.ForegroundColor = fgColor
TextWindow.Write("Background color? ")
bgColor = TextWindow.Read()
TextWindow.BackgroundColor = bgColor
TextWindow.Clear()
ShowColors()
EndWhile
Sub ShowColors
' param setBC - "True" if set background color
For i = 0 To 15
If setBC Then
If i < 7 Then
TextWindow.BackgroundColor = "Gray"
Else
TextWindow.BackgroundColor = "Black"
EndIf
EndIf
TextWindow.ForegroundColor = colors[i]
TextWindow.WriteLine(i + ". " + colors[i])
EndFor
TextWindow.WriteLine("")
EndSub
Sub GetOpositeColor
' param bgColor
' return fgColor
For i = 0 To 15
If Text.ConvertToLowerCase(bgColor) = Text.ConvertToLowerCase(colors[i]) Then
fgColor = colors[15 - i]
Goto found
ElseIF bgColor = i Then
fgColor = 15 - i
Goto found
EndIf
EndFor
TextWindow.WriteLine("Error: Invalid bgColor " + bgColor)
found:
EndSub
Sub Init
colors[0] = "Black"
colors[1] = "DarkBlue"
colors[2] = "DarkGreen"
colors[3] = "DarkCyan"
colors[4] = "DarkRed"
colors[5] = "DarkMagenta"
colors[6] = "DarkYellow"
colors[7] = "DarkGray"
colors[8] = "Gray"
colors[9] = "Blue"
colors[10] = "Green"
colors[11] = "Cyan"
colors[12] = "Red"
colors[13] = "Magenta"
colors[14] = "Yellow"
colors[15] = "White"
EndSub