By Sergey Skudaev
We continue learning how to create simple Visual Basic Application. Visit the previous page if you did not read it.
Select Project from main menu and select Add Module. Hover mouse over a thumbnail to see a large image.
Add module window displays. Select New Module and click OK
Select module from Project window and rename it to WinMain
Select Tools, Add Procedure
Type procedure name: main.
Select scope Public. Usually, it is already selected. Type inside Public Sub main procedure: "frmMain.Show"
Select Project, Project properties
On general tab type "Hello World"in project name field. In StartUp Object field select Sub Main
Double click Show Message command button on the form. Type the code:
lblMessage.Caption = "Hello World!"
Inside the Private Sub cmdShow_click() procedure. This code will be executed when user clicks Show Message Command button.
Your hello world application is ready to run. Select Run icon from main tool bar.
Visual basic prompts you to save project.
Save all project files in the start_vb folder
When you saved project, Hello World form displays. Click Show Message button. Message displays
Congratulation. You created your first Visual Basic application.
How it works?
Execution starts from sub main procedure. This procedure is defined in module as a public. It means the procedure has global scope. The code inside the sub main procedure is
frmMain.show.
frmMain is a name of the form.
Show is its method or function. When show method is executed the form displays.
When user clicks the Show Message button, button click event occurs. On button click event cmdShow_click procedure is executed. The code inside cmdShow_click procedure is
lblMessage.Caption = "Hello World!"
lblMessage is a label name. Caption is a label property. When code is executed, the string "Hello World" is assigned to label caption and is displayed on the label. The label background color, font and font color are label properties and can be set in the properties window or by code.
If you have any question or comments please register and post comments.
Password Keeper VB Application