Search Tools Links Login

VB6 Tutorial 04: First Program


This lesson will walk you through building your first Visual Basic 6 (VB6) program.

  1. Start a .exe project.
  2. Place a CommandButton on the form from ToolBox.
    New Form
  3. Click on Form and edit the caption property of the form. Write "My First VB Program".
  4. Edit the caption property of the CommandButton from the Properties Window. Write "Print".
    Control Properties
  5. Double-Click the CommandButton to open the Code Window. Write the following code.
    code window

    QuickHint:

    Write code between the two lines 'Private Sub Command1_Click()' and 'End Sub'. These two lines will be created automatically after double-clicking the CommandButton.

Explanation

'Sub' means Sub-Routine or Sub-Procedure or Function. 'Command1_Click()' is the sub-procedure name where 'Command1' is a control and 'Click' is an event. '( )' this sign indicates that 'Command1_Click()' is a function. 'Private' is the Scope. You will learn about scope in the next chapters. 'Print' is a Method.

You could also write Form1.print, where Form1 is an object and print is its method. 'End Sub' indicates the end of the sub-procedure. You will later learn about sub-procedures.

Now you are done !

Press F5 to run the program or click the start icon button from the toolbar. The code will be executed and the string "Welcome to www.fortypoundhead.com" will be displayed on the form as shown in the picture below.

program running

Writing comments

Comments are the lines of text that are not executed but used for the advantage of the programmers. Comments are written so that the other programmers can easily understand your program and you can better understand the code in case that it becomes complex or large. When you write comments, it becomes easy to maintain the code of your application. Commenting is a part of Documentation and it is a good practice to write comments.

How to write comments ?

Comments are written using the apostrophe ( ' ). That means if you write anything after apostrophe that becomes your comment and text color of the comments becomes green. See the picture below.

writing comments

About this post

Posted: 2018-03-21
By: vb6boy
Viewed: 955 times

Categories

Visual Basic 6

VB6 Tutorial

Attachments

vb60401_FirstProgram.zip
Posted: 3/25/2018 8:28:09 AM
Size: 1,177 bytes


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.