All About Visual Basic 6 Programming

Creating Your First Visual Basic Applet : A Hello World Application

Posted by Psycho Programer On Sunday, December 5, 2010 0 comments

The Hello World  program is historically the first application when one learns a new programming language. While very simple, it gives you tangible results with a minimal amount of coding, and it will give you a feel for working with Visual Basic and using IDE environment.

To create the Hello World application, follow these steps:

  1. Click File >> New Project. You might be asked to save changes to the current project if you’ve been experimenting. If so, click the No button. If you want to keep your work, click Yes. Select Standard EXE from the New Project Window.
Form

2. Resize the form by dragging its borders.

3. Select Form and change its property Name to frmHelloWorld and Caption to My First Application.

Property

4. Double-Click the Command Button control in the toolbox to create a command button of default size in the center of the form. Drag the button near the bottom center of the form.

5. Double-Click the Label control in the toolbox to create a label on the form. Drag the label so it sits just on the top of the Command Button.

Controls

6. Select Label on the form and change its Name property to lblHelloWorld, AutoSize property to True and Caption to Hello World.

7. Similarly select Command Button and change its Name property to cmdOk and Caption to Ok.

Name

8. Now double-click the cmdOk button. Double-clicking a control (or a form) opens the Code window at the default event from the control. The default event for a command button is the Click event. This means that any code entered in the procedure will be executed when the user clicks the cmdOk button.

cmdOk_Click

9. The line of code Unload Me between the Private Sub and End Sub lines tells the form to unload itself whenever the user clicks the cmdOk button. Because this is the only form in the application, it also tells the application to end.

10. Save the project by pressing Ctrl + S from the keyboard or by clicking File >> Save.

11. Click Run >> Start. If you’ve followed the directions correctly, you should see a form, similar to the one in figure below, that simply says “Hello World”.

Hello World

12. Click the Ok button to end. If things go wrong, check through the previous steps to find your mistake.

13. Now click cmdOk button and change the Caption property to &Ok . The ampersand character “&” before the first letter adds an underline to the letter O; this provides a quick keyboard alternative to a mouse-click to activate the button (here it’s Alt + O).

Shortcut

14. Run the program and now you can access the cmdOk button by pressing Alt + O on the keyboard.

HelloWorld

0 comments:

Post a Comment