Site hosted by Angelfire.com: Build your free website today!

EXTRA INFO

Getting Started with VB6

GUI

Removing the form

Getting to the Next Lesson

Code Used

 

 

EXTRA INFO

Lesson 1 (Part 3) - Coding your first program.

Getting Started with Visual Basic 6

 
IMPORTANT NOTE: If this is your first experience with VB, don't be afraid to experiment. This is hands-on stuff! Remember that VB is a Microsoft product, therefore it works with the standard Windows interface. All the functions you know from MS-Office work the same way here: Copy (Ctrl+C), Cut (Ctrl+X), Paste (Ctrl+V), the Undo button or (Ctrl+Z) and the re-do (Ctrl+Y) are great shortcuts that can help.

The first program we will write is to get a message box to display the words ‘Hello Universe ’. This is traditionally the first program that all budding programmers learn to write.

  1. Open Microsoft Visual Basic.  Start > Programs > Microsoft Visual Studio 6.0 > Microsoft Visual Basic 6.0.

  2. Click File > New Project.
  3. The “New Project” window will appear. 
  4. Select the Standard EXE icon

  5. Click      


  6. Your screen should now look something like this…




  7. We will not use a form in this program.  Click Project > Remove Form1. 

  8. The box containing the form will disappear.          

  9. In the Project menu click Project  > Add Module
  10. When the following box appears, make sure the Module icon is selected in the New tab, then click



  11. Your screen should look like this


  12. Drag the mouse through the code below to select it. Press Ctrl+C (together) on the keyboard. Click into the new blank module window and press Ctrl+V (together) this copies and pastes the code.

    Sub Main()

    MsgBox "Hello Universe, Mum and Everyone Else. I'm a Computer Programmer."

    End Sub



  13. Click the Start icon on the Standard toolbar or press F5 on the keyboard to run the program. 

  14. The message “Hello Universe. Mum and Everyone Else. I'm a Computer Programmer!” should appear on the screen in a message box.




  15. Click OK

  16. Now look at the code. The begin program code is Sub Main(). The end program code is End Sub The code in between these statements is the main program, msgbox creates a message box and the statement written in the speech marks is what appears in the message box.

    IF YOUR PROGRAM DOES NOT WORK - CLOSE DOWN VISUAL BASIC 6 (WITHOUT SAVING) AND START AGAIN.
  17. In the Module window, change the text in the speech marks to This is my second program. the whole code should look like this:

    Sub Main()

    MsgBox "This is my second program"

    End Sub


    Note the speech marks around the text to appear in the msgbox.

  18. Run the program.
  19. Now make the message box say something else that you choose.

  20. Read the code, delete it and try to re-write it yourself - copy and paste the code above if you get
    stuck.

  21. Now add 2 or more message boxes.

  22. Delete any code in the module and copy and paste this code

    Sub Main()

    Msgbox "This is my first message box. "
    Msgbox "This is my second message box. "
    Msgbox "This is my third message box. "

    End Sub

  23. As you can see there is no limit to the amount of message boxes you can create.

  24. Experiment with some message boxes of your own.

    IF YOU HAVE PROBLEMS GETTING YOUR CODE TO RUN
  • CHECK YOUR SPELLING
  • CHECK CODE IS CORRECT
  • DELETE EVERYTHING AND REPASTE THE CODE GIVEN
  • IF NOTHING WORKS CLOSE VB6 (WITHOUT SAVING) AND START AGAIN
 If everything worked that's great - if it didn't don't worry have another go from the beginning!

If you are happy with your progress click the button for the QUIZ.

Quiz1