Microsoft Small Basic

Program Listing: DWM417
' Text Converter
' Version 0.1
' Copyright © 2016 Nonki Takahashi. The MIT License.
' Last update 2016-09-10
' Challenge 2016-09

Init()
While "True"
TextWindow.WriteLine("Text?")
txt = TextWindow.Read()
DoSomething()
EndWhile

Sub Init
Not = "False=True;True=False;"
WQ = Text.GetCharacter(34)
vowel = "aeiou"
digit = "0123456789"
delim = " ,.;:!?+-*/()&|\'" + WQ
color = "1=Red;2=Yellow;3=Blue;"
nc = Array.GetItemCount(color)
EndSub

Sub DoSomething
n = Math.GetRandomNumber(4)
If n = 1 Then
Reverse()
ElseIf n = 2 Then
RedVowels()
ElseIf n = 3 Then
ColorWords()
ElseIf n = 4 Then
ReplaceNum()
EndIf
TextWindow.WriteLine("")
EndSub

Sub Reverse
' Reverse all the letters
' param txt - input text
len = Text.GetLength(txt)
rev = ""
For p = 1 To len
rev = Text.Append(Text.GetSubText(txt, p, 1), rev)
EndFor
TextWindow.WriteLine(rev)
EndSub

Sub RedVowels
' Echo with all vowels in red
' param txt - input text
len = Text.GetLength(txt)
For p = 1 To len
c = Text.GetSubText(txt, p, 1)
If Text.IsSubText(vowel, Text.ConvertToLowerCase(c)) Then
TextWindow.ForegroundColor = "Red"
Else
TextWindow.ForegroundColor = "Gray"
EndIf
TextWindow.Write(c)
EndFor
TextWindow.ForegroundColor = "Gray"
TextWindow.WriteLine("")
EndSub

Sub ColorWords
' Color the words Red, Yellow, Red etc
' param txt - input text
len = Text.GetLength(txt)
p = 1
While p <= len
GetWord()
TextWindow.ForegroundColor = color[Math.GetRandomNumber(nc)]
TextWindow.Write(word)
EndWhile
TextWindow.ForegroundColor = "Gray"
TextWindow.WriteLine("")
EndSub

Sub GetWord
' Get a word from a text
' param txt - input text
' param len - length of the text
' param p - pointer to the text
' param delim - delimiter to separate words
' return word
' return p - updated pointer
word = ""
c = Text.GetSubText(txt, p, 1)
If Text.IsSubText(delim, c) And (p <= len) Then
word = c
p = p + 1
Else
While Not[Text.IsSubText(delim, c)] And (p <= len)
word = Text.Append(word, c)
p = p + 1
c = Text.GetSubText(txt, p, 1)
EndWhile
EndIf
EndSub

Sub ReplaceNum
' Replace all numbers with an *
' param txt - input text
len = Text.GetLength(txt)
For p = 1 To len
c = Text.GetSubText(txt, p, 1)
If Text.IsSubText(digit, c) Then
TextWindow.Write("*")
Else
TextWindow.Write(c)
EndIf
EndFor
TextWindow.WriteLine("")
EndSub