Write Your First Visual Basic Program

Lesson 1
Tutorials - Page 1 - Page 2 - Page 3 - Page 4 - Page 5 - Page 6 - Page 7 - Page 8 - Page 9 - Page 10 - Page 11

The Command Button's Events (Continue)
To learn about more events, we will use the "Print" command.
The "Print" command simply writing a text on the form.
For example, the following line:

Print "Hello"

Will write "Hello" on the form (Figure 25)

Figure 25

Add another Command Button to your form.
The New Command Button's name is "Command2" by default (Figure 26)

Figure 26


Now, rewrite the Command1 Click event and insert the
following line to it:

Print "This is Command1"

Select "Command2" (This is the name of the second
Command Button) from the Components list (Figure 23),
And select "Click" from the Command2 events List.

Enter the following line to the Command2_Click event:

Print "This is Command2"

After you've done so, your code should look like this:


Private Sub Command1_Click()
    Print "This is Command1"
End Sub

Private Sub Command2_Click()
    Print "This is Command2"
End Sub


Run the program.
When you are clicking on Command1 Button, the text "This is Command1"
appears on the form, and when you are clicking on Command2 Button,
the text "This is Command2" appears on the form.


Proceed to Lesson 2 to learn about variables.

Back  Forward