Microsoft Small Basic

Program Listing: PGM326
'Curriculum Challenge 1.4
'(1) Write a program that loops through the first 100 numbers, 1, 2, 3 ... 99, 100.
' It then Writes out to the TextWindow every number that is a multiple of 3 or 7.

Input()
Calculate()
Output()
'-------------------------------1st Level Subroutines---------------------------------------------------
Sub Calculate
For j = 1 To Array.GetItemCount(divisibleBy)
For i = checkIntegersFrom To checkIntegersTo
If Math.Remainder(i, divisibleBy[j]) = 0 Then
n = n + 1
answer[n][divisibleBy[j]] = i
EndIf
EndFor
EndFor
EndSub

Sub Input
While Text.GetLength(checkIntegersFrom) < 1
TextWindow.Write("Loop through Integers from ")
InputError()
checkIntegersFrom = TextWindow.Read()
If Text.GetLength(checkIntegersFrom) < 1 Then
TextWindow.Clear()
TurnAstrixSwitchOn()
TextWindow.WriteLine("")
EndIf
EndWhile
TextWindow.Clear()
TextWindow.Write("Loop through Integers from ")
TextWindow.Write(checkIntegersFrom)
While Text.GetLength(checkIntegersTo) < 1
TextWindow.Write(" to ")
InputError()
checkIntegersTo = TextWindow.Read()
If Text.GetLength(checkIntegersTo) < 1 Then
TextWindow.Clear()
TurnAstrixSwitchOn()
TextWindow.WriteLine("")
TextWindow.Write("Loop through Integers from " + checkIntegersFrom)
EndIf
EndWhile
TextWindow.Clear()
FirstLineOfInputSoFar()
TextWindow.WriteLine("")
While Text.GetLength(numberOfDivisors) < 1
TextWindow.Write("Using how many different Divisors? ")
InputError()
numberOfDivisors = TextWindow.Read()
If Text.GetLength(numberOfDivisors) < 1 Then
TextWindow.Clear()
TurnAstrixSwitchOn()
TextWindow.WriteLine("")
FirstLineOfInputSoFar()
TextWindow.WriteLine("")
EndIf
EndWhile
TextWindow.Clear()
up:
FirstLineOfInput()
TextWindow.WriteLine("")
For i = 1 To numberOfDivisors
TextWindow.Write("Enter divisor " + i + ": ")
If astrixSwitch = "ON" Then
TextWindow.ForegroundColor = "red"
TextWindow.Write("*")
TextWindow.ForegroundColor = "gray"
EndIf
divisibleBy[i] = TextWindow.ReadNumber()
EndFor
astrixSwitch = "OFF"
For i = 1 To numberOfDivisors
If divisibleBy[i] < 1 Then
TextWindow.Clear()
TextWindow.ForegroundColor = "red"
TextWindow.Write("You need enter " + numberOfDivisors)
TextWindow.WriteLine(" divisor/s > 0.")
TextWindow.ForegroundColor = "gray"
TurnAstrixSwitchOn()
TextWindow.WriteLine("")
Goto up
EndIf
EndFor
EndSub

Sub Output
TextWindow.Clear()
TextWindow.ForegroundColor = "green"
TextWindow.Write("Returning Integers from " + checkIntegersFrom)
TextWindow.Write(" to " + checkIntegersTo + " divisible by ")
If Array.GetItemCount(divisibleBy) = 1 Then
TextWindow.Write(divisibleBy[1])
ElseIf Array.GetItemCount(divisibleBy) = 2 Then
TextWindow.Write(divisibleBy[1])
TextWindow.Write(" and ")
TextWindow.Write(divisibleBy[2])
Else
For j = 1 To Array.GetItemCount(divisibleBy)-1
TextWindow.Write(divisibleBy[j] + ",")
EndFor
TextWindow.Write("and ")
TextWindow.Write(divisibleBy[Array.GetItemCount(divisibleBy)])
EndIf
TextWindow.WriteLine(".")
For j = 1 To Array.GetItemCount(divisibleBy)
TextWindow.WriteLine("")
TextWindow.ForegroundColor = "blue"
TextWindow.WriteLine("Divisible by: " + divisibleBy[j])
TextWindow.ForegroundColor = "gray"
For i = 1 To Array.GetItemCount(answer)
If answer[i][divisibleBy[j]] > 0 Then
TextWindow.Write(answer[i][divisibleBy[j]] + ",")
EndIf
EndFor
TextWindow.WriteLine("")
EndFor
TextWindow.WriteLine("")
EndSub
'---------------------------------------2nd Level Subroutines------------------------------------------
Sub InputError
If astrixSwitch = "ON" Then
TextWindow.ForegroundColor = "red"
TextWindow.Write("*")
TextWindow.ForegroundColor = "gray"
astrixSwitch = "OFF"
EndIf
EndSub

Sub TurnAstrixSwitchOn
astrixSwitch = "ON"
TextWindow.ForegroundColor = "red"
TextWindow.WriteLine("*Entry Required")
TextWindow.ForegroundColor = "gray"
EndSub

Sub FirstLineOfInputSoFar
TextWindow.Write("Loop through Integers from " + checkIntegersFrom)
TextWindow.WriteLine(" to " + checkIntegersTo + ".")
EndSub

Sub FirstLineOfInput
TextWindow.Write("Loop through Integers from " + checkIntegersFrom)
TextWindow.Write(" to " + checkIntegersTo + ".")
TextWindow.WriteLine(" Using " + numberOfDivisors + " divisor/s.")
EndSub