Freigeben über


Small Basic #2: Working with the Text Window

This is the first of many posts that demonstrates how to use Microsoft Small Basic to program computers. This post assumes that you've already downloaded and installed Small Basic and that you've already read at least the first 10 pages of the Getting Started Guide. We'll start with a discussion of the text window, a window that provides text-related input and output functionalities. For example, you can use the text window to get some text and numbers from users and also to write some text and numbers to the computer screen.

Try running this code: copy the following code, paste it into an Untitled Small Basic editor window, and then press the F5 key (or, on the toolbar, click Run (F5) ).

 ' Display the text window and clear its contents.
' Show and Clear are not really needed here, but they are included for demonstration.
TextWindow.Show()
TextWindow.Clear()

' Highlight the text window's text in yellow and change the text's color to blue.
TextWindow.BackgroundColor = "Yellow"
TextWindow.ForegroundColor = "Blue"

' Position the cursor 15 columns from the left and 10 rows from the top of the text window.
TextWindow.CursorLeft = 15
TextWindow.CursorTop = 10

' Position the text window 200 pixels to right and 400 pixels down from the upper-left edge of the screen.
TextWindow.Left = 200
TextWindow.Top = 400

' Set the text window's title bar text.
TextWindow.Title = "This is My Title!"

' Get information from the user and then display it back to the user.
TextWindow.WriteLine("Type some text:")
myText = TextWindow.Read()
TextWindow.WriteLine("Type a number:")
myNumber = TextWindow.ReadNumber()
TextWindow.Write("You typed " + myText + " and " + myNumber + ". ")

' Wait for the user to do something and then hide the text window.
' Pause and Hide are not really needed here, but they are included for demonstration.
TextWindow.Pause()
TextWindow.Hide()

You may notice a few things here:

  • BackgroundColor is a property, which is a characteristic or attribute of the text window. "Yellow" and "Blue" are property values of the BackgroundColor property. There are other valid property values that you can use here, such as "Green" and "Magenta."
  • myText and myNumber are variables. You can use variables to store values temporarily and then use them later.
  • The parentheses are used to give arguments, or special information, to WriteLine, a method of the TextWindow object. An object can do something, and a method is something that can be done to an object. Note that empty parentheses mean that no special arguments need to be given to that method.

Comments

  • Anonymous
    March 11, 2014
    this was very helpfull with my revision and i will be visiting this site rugulary thank you.