Microsoft Small Basic support pages
A summary of some of the commands useful with the GCSE programming tasks

The text window:

Text Window properties:

  • TextWindow.ForegroundColor - Gets or sets the foreground colour of the text to be output in the text window.
  • TextWindow.BackgroundColor - Gets or sets the background colour of the text to be output in the text window (follow with TextWindow.Clear() to fill the whole text box with that colour).
  • TextWindow.CursorLeft - Gets or sets the cursor's column position on the text window.
  • TextWindow.CursorTop - Gets or sets the cursor's row position on the text window.  
  • TextWindow.Left - Gets or sets the Left position of the Text Window.
  • TextWindow.Title - Gets or sets the Title for the text window.
  • TextWindow.Top - Gets or sets the Top position of the Text Window.

 Text Window Operations:

  • TextWindow.Show() - Shows the Text window to enable interactions with it.
  • TextWindow.Hide() - Hides the text window.
  • TextWindow.Clear() - Clears the TextWindow.
  • TextWindow.Pause() - Waits for user input before returning.
  • TextWindow.PauseIfVisible() - Waits for user input only when the TextWindow is already open.
  • TextWindow.PauseWithoutMessage() - Waits for user input before returning.
  • TextWindow.Read() - Reads a line of text from the text window after the user hits ENTER.
  • TextWindow.ReadKey() - Reads a single character from the text window.
  • TextWindow.ReadNumber() - Reads a number from the text window after the user hits ENTER. TextWindow.WriteLine(data) - Writes text or number to the text window plus a new line character.
  • TextWindow.Write(data) - Writes text or number to the text window.

File Handling:

File Properties:

  • File.LastError - Gets or sets the last encountered file operation based error message.

File Operations:

  • File.ReadContents(filePath) - Opens a file and reads the entire file's contents. Fast for small files that are less than 1 MB in size
  • File.WriteContents(filePath, contents) - Opens a file and writes the specified contents into it, replacing the original contents with the new content.
  • File.ReadLine(filePath, lineNumber) - Opens the specified file and reads the contents at the specified line number.
  • File.WriteLine(filePath, lineNumber, contents) - Opens the specified file and writes or overwrites the contents at the specified line number.
  • File.InsertLine(filePath, lineNumber, contents) - Opens the specified file and inserts (but will not over write) the contents at the specified line number.
  • File.AppendContents(filePath, contents) - Opens the specified file and appends the contents to the end of the file.
  • File.CopyFile(sourceFilePath, destinationFilePath) - Copies the specified source file to the destination file path. If the destination points to a location that doesn't exist, the method will attempt to create it automatically. Existing files will be overwritten.
  • File.DeleteFile(filePath) - Deletes the specified file.
  • File.CreateDirectory(directoryPath) - Creates the specified directory.
  • File.DeleteDirectory(directoryPath) - Deletes the specified directory.
  • File.GetFiles(directoryPath) - Gets the path of all the files in the specified directory path.
  • File.GetDirectories(directoryPath) - Gets the path of all the directories in the specified directory path.
  • File.GetTemporaryFilePath() - Creates a new temporary file in a temporary directory and returns the full file path.
  • File.GetSettingsFilePath() - Gets the full path of the settings file for this program.

Examples:

To save the contents of a variable called "contents" into a file called "data.txt" in the same directory as your program file use:

  • File.WriteContents(Program.directory + "\data.txt",contents)

To load the entire contents of a file "data.txt" into a variable "contents" from the same directory as your program file use:

  • contents = File.ReadContents(Program.directory + "\data.txt")

Arrays

Operations:

  •  Array.ContainsIndex(array, index) - Gets whether or not the array contains the specified index.
  • Array.ContainsValue(array, value) - Gets whether or not the array contains the specified value.
  • Array.GetAllIndices(array) - Gets all the indices for the array as another array, indexed numerically starting at 1.
  • Array.GetItemCount(array) - Gets the number of items stored in the array.
  • Array.IsArray(array) - Gets whether or not a given variable is an array.

Examples:

A simple indexed array:

colour[1] = "Red"
colour[2] = "Amber"
colour[3] = "Green"

To show the contents of this array:

  • TextWindow.WriteLine(colour)
    The output would be:  1=Red;2=Amber;3=Green;

To show just one value in this array:

  • TextWindow.WriteLine(colour[2])
    The output would be:  Amber

To check if this array contains a particular value:

  • TextWindow.WriteLine(Array.ContainsValue(colour, "Amber"))
    The output would be:  True

A more complex indexed array:

contact["Name"] = "Joe Bloggs"
contact["Phone"] = "07345678901"
contact["Postcode"] = "EX5 7DE"

To check if this array contains a particular index:

  • TextWindow.WriteLine(Array.ContainsIndex(contact,"Phone"))
    The output would be:  True

To list the indexes used in this array:

  • TextWindow.WriteLine(Array.GetAllIndices(contact))
    The output would be:  1=Name;2=Phone;3=Postcode;

To store an unknown number of colours in an array:

continue = "True"
colourNumber = 0
While continue = "True"
  TextWindow.Write("Enter a colour (or blank to finish)")
  colourEntered = TextWindow.Read()
  If colourEntered = "" Then
     continue = "False"
  Else colourNumber = colourNumber + 1
     indexName = "Colour" + colourNumber
     colourStored[indexName] = colourEntered
  EndIf
EndWhile

To output the contents of this array if the user entered Red then Amber then Green then nothing:

  • TextWindow.WriteLine(colourStored)
    The output would be:  Colour1=Red;Colour2=Amber;Colour3=Green;