Your First Visual Basic 6 Program

  
This is your first Visual Basic program, an easy program to introduce you to VB programming.

Step 1: Start a .exe project. 
Step 2: Place a CommandButton on the form from ToolBox.


your first easiest vb program
 
Step 3: Click on Form and edit the caption property of the form. Write "My First VB Program".
Step 4: Edit the caption property of the CommandButton from the Properties Window. Write "Print".

Shows how to set properties at design time



Step 5: Double-Click the CommandButton to open the Code Window. Write the following code.



Write your code in this window
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.vbtutes.com" will be displayed on the form as shown in the picture below.

Output of your first vb program



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 16px. 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.
Write comments when necessary