Contents
Greetings  Sample Help

Sample Description: Greetings

Points of Interest

Playing a Sound File at Startup

Making Text Roll up the Screen

Centering a Control on a Form

Changing a Label’s Font

Control

Timer

Label

For Help on Help, Press F1


Greeting

The purpose of the Greeting sample is to show several techniques that can be applied when building applications. The Greetings form itself is not a finished application, rather it is a set of techniques for producing various types of functionality.

To run this sample:

•	Click the Play button. A sound recording will be played, then a greeting label will dynamically scroll up the screen.


Playing a Sound File at Startup

The sound function created for this sample is designed to play a sound (.wav) file that is stored on your hard drive. Currently, the Sub procedure PlayGreetings is called from the Play button. To make your application play a sound file at startup, you need to put this instruction in the form’s Load method.

To play a greeting file, your application should know the name of the sound file(s) and their directory location. To actually play the sound file, the following program code is required:

Sub PlayGreetings()

  Dim option As long

  Dim result As long

  Dim greeting_part1 As String

  Dim greeting_part2 As String

  greeting_part1 = GreetingMaster.SampleDir & "professr.wav"

  greeting_part2 = GreetingMaster.SampleDir & "wargames.wav"

  result = AudioPlayer.sndPlaySoundA(greeting_part1, option)

  result = AudioPlayer.sndPlaySoundA(greeting_part2, option)

End Sub

That’s all there is to playing a sound file from your application. The "option" parameter does not have to be configured, but must be passed to satisfy the sndPlaySound declaration statement. The AudioPlayer object is the object that declares the audio function as shown below:

Declare Function sndPlaySoundA Lib "Winmm" (ByVal file As String, ByVal opt As Long) As Long

The sound file is played through the Windows API function declared above.


Making Text Roll up the Screen

Making text roll up the screen is done by changing the location of a label control so that the text inside it moves as the label is moved. With the BackColor of the label matching the BackColor of the form, it appears that text is dynamically moving up the screen.

To make the label move "dynamically," a Timer control event moves the previously located label in small increments from the bottom to the center of the screen. The Play button activates the Timer control, which calls the following function at each timer interval:

Sub GreetingTimer_Timeout()

  Dim target_top As Integer

  target_top = (GreetingMasterForm.ScaleHeight - lblGreetings.Height) / 2

  ' Move the welcome sign up 60 pixels at a time

  lblGreetings.Top = lblGreetings.Top - 60

  lblGreetings.Refresh

  ' If the greeting sign is in position, turn off the timer

  If lblGreetings.Top <= target_top Then GreetingTimer.Enabled = False

End Sub

This method is called each time a timer interval passes. In this sample, an object named GreetingTimer is used as the application timer. Its Interval property is set to 1. When the timer is enabled by the Play button, the Timeout method is executed at each interval period. The greeting label is moved up 60 pixels at each timer interval. When the label reaches a certain point on the form (near the center), its Visible property is set to False to make the label disappear.


Centering a Control on a Form

In this sample, a greeting label is made visible and scrolled up the screen by a timer event. To make sure the label is centered on the form, the following code is executed before the Timer is enabled.

' Now we move the greetings into position

  lblGreetings.Top = GreetingMasterForm.Top + GreetingMasterForm.ScaleHeight

  lblGreetings.Left = (GreetingMasterForm.ScaleWidth / 2) - (lblGreetings.Width / 2)

  lblGreetings.Visible = True

The lblGreeting label is automatically centered on the form by taking the label’s Width and the form's ScaleWidth into account.


Changing a Labels Font
Changing a Label’s Font

In this sample, a greetings label dynamically scrolls up the form when the Play button is clicked. The label contains the text string "Welcome to the Games Demonstration." The font is much larger than the default font. The label's font reference (>>Font) is linked to a Font object named LargeFont. The LargeFont object was embedded into the form’s property list and set to a large font. To change the color of the font, the label's ForeColor property was set to blue.