Easy VB6 Samples


Your first VB program

This is your first Visual Basic program. This program demonstrates the use of  'print' method.         

                                                   >> DOWNLOAD


Code:
Private Sub Command1_Click()
    Print "Welcome to www.vbtutes.com"
End Sub
___________________________________________________________________________



Example of MouseMove

Example of MouseMove demonstrates the MouseMove event. In this program, when you move the mouse on the form, the block of code in the MouseMove event procedure is executed. As a result, the form becomes larger in size.

Example of MouseMove event             
                                                   >> DOWNLOAD

Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Form1.Height = Form1.Height + 5
    Form1.Width = Form1.Width + 5
End Sub
___________________________________________________



Example of MouseDown & MouseUp

Example of MouseDown & MouseUp shows the use of MouseDown and MouseUp event. It is showed in a textbox whether a MouseDown or a MouseUp event is invoked.




sample program to show MouseDown & MouseUp events          
              
                                     >> DOWNLOAD

Code:
Private Sub cmdClear_Click()
    Text1.Text = ""
End Sub
_________________________________________________________________
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.Text = ""
    Text1.Text = "MouseDown event"
 

End Sub                                            
_________________________________________________________________
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.Text = ""
    Text1.Text = "MouseUp event" 
End Sub                
_______________________________________________________________   



Example of GotFocus event

Example of GotFocus event shows the application of GotFocus event. There are some objects on the form of the project. When an object gets the focus, the form's background color is changed.


example program of GotFocus event             
     
                                                 >> DOWNLOAD  
Code:
Private Sub Command1_GotFocus()
    Form1.BackColor = vbBlack
End Sub
______________________________________________
Private Sub Command2_gotfocus()
    Form1.BackColor = vbGreen
End Sub
______________________________________________
Private Sub Picture1_GotFocus()
    Form1.BackColor = vbWhite
End Sub
______________________________________________
Private Sub Text1_GotFocus()
    Form1.BackColor = vbRed
End Sub
_________________________________________________________




Using Option Explicit statement

Program 5 shows how the Option Explicit statement works.



showing the use of option explicit statement
             
                                                   >> DOWNLOAD

Code:
Option Explicit      'in Declarations section
_________________________________________________
Private Sub Command1_Click()
    Dim n As Integer  'You must declare n,otherwise 

    n = 20            'it will show error
    Print n + 1
End Sub
___________________________________________________________




General Declaration

The General Declaration program shows what actually happens when a variable is declared in the Declarations section.

Learn about:


Variable declaration in general declaration section
             
                                                   >> DOWNLOAD

Code:
'Declarations section
Dim n As Integer   'n is accessible from all the procedures
________________________________________________________________
Private Sub cmdShow1_Click()
    n = 7
    Print n
End Sub
________________________________________________________________
Private Sub cmdShow2_Click()
    Print n + 1
End Sub
______________________________________________________________



Clicks Counter

Clicks Counter demonstrates the use of static variable. This program displays the number of clicks the user has made. That means it counts the user-clicks.

Learn about static variables at:

Clicks counter program uses static variable to display the number of clicks
             
                                                   >> DOWNLOAD

Code:
Private Sub cmdClick_Click()
    Static n As Integer
    n = n + 1
    Print n
End Sub
____________________________________________________



Set properties

The Set properties program shows you several useful properties.


Learn about:

The sample program showing how to set properties
             
                                                   >> DOWNLOAD
Code:
Private Sub cmdSet_Click()
                   'BackColor and ForeColor Properties
    Label1.BackColor = vbRed
    Label1.ForeColor = vbBlue
    Form1.BackColor = vbGreen
    Text1.BackColor = vbBlack
    Text1.ForeColor = vbYellow
    Frame1.BackColor = vbWhite

                   'Font properties
    Text1.FontSize = 16
    Text1.FontBold = True
    Text1.FontItalic = True
    Text1.Font = "Tahoma"
            
                  'Caption property
    Form1.Caption = "New Program"
    Label1.Caption = "Hello"
    Frame1.Caption = "New frame"


                  'text property
    Text1.Text = "New Program"
End Sub