TechnologyUK - Programming (VB6) Logo

A First Application

We'll start with a typical "Hello World" application. All it does is display the words "Hello World" when the user presses a button, but it demonstrates the steps involved in creating an application. Carry out the following steps to create the application:

  1. Start Visual Basic (accept the Standard.EXE option - this will be highlighted by default). VB creates a new application with a blank form.
  2. Using the mouse, left-click on the command button control in the toolbox to select it, then move the cursor to the form and drag out a rectangular shape. When the left mouse button is released, a command button will appear on the form.
  3. Click once on the button to select it, and press F4 to bring up the button's property window. Find and highlight the CAPTION property, and replace the existing text (Command1) with the word Message to change the text on the command button.
  4. Double click on the button to bring up the form's code window. Each type of control recognises certain events. In this example, a left mouse click on the button is the event which corresponds to pressing the button, and which triggers the associated code to execute. When you bring up the code window by double-clicking on the button, the command1_click() event procedure will appear, with the cursor in the correct position to allow you to enter the code.
  5. Type the following: MsgBox ("Hello World")
  6. Press the F5 button to run the program. The application will appear as a single window with a button labeled "Message". Click on the button to see a message box with the words "Hello World" appear. Click on the OK button to close the message box. You have now written a Visual Basic application! Click on the application's "X" button to close the form and return to the IDE.