2.4 sound, program, and text objects

11
Microsoft® Small Basic Sound, Program, and Text Objects Estimated time to complete this lesson: 1 hour

description

 

Transcript of 2.4 sound, program, and text objects

Page 1: 2.4   sound, program, and text objects

Microsoft® Small Basic

Sound, Program, and Text Objects

Estimated time to complete this lesson: 1 hour

Page 2: 2.4   sound, program, and text objects

Sound, Program, and Text Objects

In this lesson, you will learn about:

Using the Program object to manage execution of Small Basic programs.

Using the Sound object to enable playback of sounds in Small Basic programs.

Using the Text object to work with text-related functions in Small Basic programs.

Page 3: 2.4   sound, program, and text objects

Introduction to the Program Object

To better understand the Program object, let’s take a look at the example displayed.

When creating programs and working with various objects and operations offered by Small Basic, you might want to control the execution of your program. You can use the Program object to manipulate how your program executes.

In this example, notice the use of Delay and End operations. The Delay operation sets a fixed time delay for the program to execute, and the End operation ends the program execution.

OUTPUT

Page 4: 2.4   sound, program, and text objects

Exploring the Program Object

The Program object also allows you to retrieve information about the arguments passed to your program.

Let’s take a look at an example to understand how you can use the Program object to determine the count and value of arguments passed to a program during execution.

Page 5: 2.4   sound, program, and text objects

Introduction to the Sound Object

After working with arguments and using the Program object, let’s explore some other interesting aspects of Small Basic.

Did you know that you could include sounds in your Small Basic programs?In fact, you can choose from sample sounds provided in the Small Basic library.

Look at the example displayed. You can work with sounds in your program by using the Sound object with operations such as Play, Pause, and Stop.

The output of this example plays, pauses, and stops the specified sound file at regular intervals.

Page 6: 2.4   sound, program, and text objects

Now, let’s take a look at an example to understand how you can play specific sounds, such as a bell ring, chime, or click, in your Small Basic program.

Exploring the Sound Object

Observe the use of the PlayAndWait operation in the example. The PlayAndWait operation plays an audio file and waits until the audio has finished playing.

The output will play the sound of a bell ringing, a chime, and a click, at regular intervals.

Page 7: 2.4   sound, program, and text objects

Small Basic also offers useful operations that help you work with text.

Introduction to the Text Object

For example, you may want to convert all names to uppercase. Alternatively, you may want to find out whether a portion of text contains specific information.

In Small Basic, when working with text, you can use the Text object and its various functions and methods to perform operations on the text.

For example, to find out the length of a text string, you can use the GetLength operation.

Let’s learn some more operations of the Text object with an example...

Page 8: 2.4   sound, program, and text objects

More on the Text Object

Let’s take a look at another example to understand some more operations of the Text object.

In this example, the user inputs an e-mail address. Using the IsSubText operation of the Text object, you can determine whether the e-mail address is valid or not.

Page 9: 2.4   sound, program, and text objects

Operations of the Text Object

Another operation of the Text object is the GetSubText operation. This operation takes three parametersthe text from which you want to derive the subtext, the location from where you want to derive the subtext, and the length up to which you want to derive the subtext.

Here are some more uses of the Text object…

To determine whether given text starts with specified subtext, you can use the StartWith or EndWith operations.

To get the character code for a specific Unicode character, you can use the GetCharacterCode operation.

To determine the index position of specific subtext, you can use the GetIndexOf operation.

Page 10: 2.4   sound, program, and text objects

Let’s Summarize…

Congratulations! Now you know how to:

Use the Program object to manage the execution of a Small Basic program.

Use the various operations of the Sound object to include sounds in your Small Basic program.

Use the Text object to operate on text in your Small Basic program.

Page 11: 2.4   sound, program, and text objects

It’s Time to Apply Your Learning…

Write a program that displays a text window and perform the following steps:

Ask the user to type an answer to a simple question.

If the answer is correct, the program must display a success message along with a chime sound.

If the answer is incorrect, the program must display the appropriate message along with the sound of a bell.