Microsoft Small Basic

Program Listing: XMX755
'Single character String Searcher - beta V0.1, 8/05/2013 by Jibba Jabba
'Extra features have been added.
'Curriculum Challenge 1.4 May2013
'(2) Write a program that gets some text input by the user and loops through
'each character and counts the number of vowels a, e, i, o or u.
'------------------------------Main Program--------------------------------------------
continue = "y"
While continue = "y"
TextWindow.Clear()
InitVar()
StringInput()
SearchInput()
Search()
ShowResults()
ContinuePrompt()
Exit()
EndWhile
'--------------------------------Main Subroutines-----------------------------------------
Sub InitVar
criteria = ""
i = 0
EndSub

Sub StringInput
TextWindow.ForegroundColor = "Green"
TextWindow.CursorLeft = 1
TextWindow.WriteLine("Curriculum Challenge 1.4")
TextWindow.ForegroundColor = "cyan"
TextWindow.CursorLeft = 8
TextWindow.CursorTop = 5
TextWindow.WriteLine("This program will seach through a string of text")
TextWindow.ForegroundColor = "Gray"
TextWindow.CursorLeft = 8+6
TextWindow.CursorTop = 7
TextWindow.WriteLine("Enter the string to search through")
TextWindow.CursorLeft = 8+4
TextWindow.CursorTop = 7+3
inputString = Text.ConvertToLowerCase(TextWindow.Read())
TextWindow.Clear()
EndSub

Sub SearchInput
StringInputTitle()
SearchInputTitle()
ContinuePrompt()
i = 0
While continue = "y"
TextWindow.Clear()
StringInputTitle()
SearchInputTitle()
ShowSearchInputs()
i = i + 1
TextWindow.Write("Type a character " + i + ": ")
criteria[i] = Text.ConvertToLowerCase(TextWindow.ReadKey())
TextWindow.WriteLine(criteria[i])
TextWindow.WriteLine("")
If criteria[i] = Text.GetCharacter(27) Then 'using ESC key
criteria[i] = ""
Goto down
ElseIf criteria[i] = Text.GetCharacter(13) Then 'using ENTER key
criteria[i] = Text.GetCharacter(2)
EndIf
EndWhile
down:
EndSub

Sub Search
For j = 1 To Array.GetItemCount(criteria)
n = 0
For i = 1 To Text.GetLength(inputString)
If Text.GetSubText(inputString, i, 1) = criteria[j] Then
n = n + 1
position[criteria[j]][n] = i
EndIf
EndFor
EndFor
EndSub

Sub ShowResults
TextWindow.Clear()
ShowResultsTitle()
StringInputTitle()
For i= 1 To Array.GetItemCount(criteria)
TextWindow.ForegroundColor = "Cyan"
TextWindow.Write("The letter ")'added writeline, repos cursor DEBUG
TextWindow.ForegroundColor = "yellow"
TextWindow.Write(criteria[i])
TextWindow.ForegroundColor = "Cyan"
TextWindow.Write(" appears ")
TextWindow.ForegroundColor = "yellow"
TextWindow.Write(Array.GetItemCount(position[criteria[i]]))
TextWindow.ForegroundColor = "Cyan"
TextWindow.Write(" times. At positions: ")
TextWindow.ForegroundColor = "yellow"
For j = 1 To Array.GetItemCount(position[criteria[i]])
TextWindow.Write(position[criteria[i]][j] + ", ")
EndFor
TextWindow.WriteLine("")
EndFor
TextWindow.WriteLine("")
TextWindow.ForegroundColor = "white"
EndSub

Sub ContinuePrompt
TextWindow.ForegroundColor = "white"
TextWindow.WriteLine("Continue? y ")
continue = Text.ConvertToLowerCase(TextWindow.ReadKey())
TextWindow.ForegroundColor = "gray"
EndSub

Sub Exit
If continue <> "y" Then
TextLogo()
Program.End()
EndIf
EndSub
'--------------------------Sub Subroutines----------------------------------------------
Sub StringInputTitle
TextWindow.ForegroundColor = "cyan"
TextWindow.Write("You entered: ")
TextWindow.ForegroundColor = "Green"
TextWindow.Write(inputString)
TextWindow.ForegroundColor = "cyan"
TextWindow.WriteLine(":")
TextWindow.ForegroundColor = "gray"
TextWindow.WriteLine("")
EndSub

Sub SearchInputTitle
TextWindow.Write("Quick Input Mode - press ")
TextWindow.ForegroundColor = "red"
TextWindow.Write("ESC")
TextWindow.ForegroundColor = "gray"
TextWindow.WriteLine(" to finish")
TextWindow.WriteLine("")
EndSub

Sub ShowSearchInputs
For k = 1 To Array.GetItemCount(criteria)
TextWindow.WriteLine("Searching for: " + criteria[k])
EndFor
TextWindow.WriteLine("")
EndSub

Sub ShowResultsTitle
TextWindow.ForegroundColor = "green"
TextWindow.WriteLine("Results:")
TextWindow.WriteLine("")
EndSub

Sub TextLogo
character = "1=!;2=@;3=#;4=$;5=%;6=^;7=+"
red = "1=yellow;2=white;3=gray;4=red;5=black;6=blue"
green = "7=cyan;8=green;9=magenta;10=darkblue;11=darkcyan"
blue = "12=darkgray;13=darkgreen;14=darkmagenta;15=darkred;16=darkyellow"
colour = red + green + blue
logoWord = "1=Jibba;2=Jabba"
TextWindow.Clear()
For i = 1 To 110
TextWindow.BackgroundColor = (colour[Math.GetRandomNumber(16)])
TextWindow.Write(character[Math.GetRandomNumber(7)])
Program.Delay(Math.GetRandomNumber(15))
EndFor
TextWindow.BackgroundColor = "black"
TextWindow.ForegroundColor = "yellow"
TextWindow.Write(" by " + logoWord[1] +" " + logoWord[2])
Program.Delay(900)
TextWindow.ForegroundColor = "gray"
TextWindow.Clear()
EndSub