Some Simple VB6 Examples


Form Design

The Form Design program shows you many ways of designing a vb form.


Learn about properties: 

Form design with different form properties
             
                                                   >> DOWNLOAD
 
Code:
Private Sub cmdBlack_Click()
    Form1.BackColor = vbBlack             
End Sub
________________________________________
Private Sub cmdChangePosition_Click()
    Form1.Top = 5000
    Form1.Left = 5000
End Sub
________________________________________
Private Sub cmdDefault_Click()
    Form1.BackColor = &H8000000F
    Form1.Width = 4500
    Form1.Height = 4125
    Form1.Top = 900
    Form1.Left = 900
End Sub
________________________________________
Private Sub cmdEnlarge_Click()
    Form1.Width = 5160
    Form1.Height = 4770
End Sub
________________________________________
Private Sub cmdGreen_Click()
    Form1.BackColor = vbGreen
End Sub
________________________________________
Private Sub cmdMakeSmaller_Click()
    Form1.Width = 4500
    Form1.Height = 4125
End Sub
________________________________________
Private Sub cmdRed_Click()
    Form1.BackColor = vbRed
End Sub
________________________________________
Private Sub cmdWhite_Click()
    Form1.BackColor = vbWhite
End Sub
________________________________________
Private Sub Form_Load()
    Form1.Top = 900
    Form1.Left = 900
End Sub
_________________________________________________________________



Password Program

Password Program demonstrates the 'PasswordChar' property of TextBox. If correct password is entered, the program displays a success message. This is a very important concept as it can be implemented in some real life software projects.


Learn about label and text box: 

This is a password related program that uses PasswordChar property
             
                                                   >> DOWNLOAD

Code:

Private Sub cmdConfirm_Click()
    If txtField.Text = "12345" Then
        MsgBox "Successful !!!", vbInformation, ""
    Else
        MsgBox "Incorrect Password !", vbCritical, ""
    End If
End Sub
_________________________________________
Private Sub cmdClear_Click()
    txtField.Text = ""
End Sub
_________________________________________________________________




Tool Tip Text

Program 9 lets you know about the 'Tool Tip Text' property. This is generally implemented in all modern software.


Learn about label and text box: 

Learn about tool tip text
             
                                                   >> DOWNLOAD
___________________________________________________________


Text Dispay 1

Program 11 shows the basic functionality of TextBox. It shows how text is displayed in the TextBox object.

Find more about textbox at:  

The program shows message in text box
             
                                                   >> DOWNLOAD
Code:
Private Sub cmdShow_Click()
    txtField.Text = "Hello World"
End Sub
__________________________________
Private Sub cmdExit_Click()
    End
End Sub
__________________________________
Private Sub cmdClear_Click()
    txtField.Text = ""
End Sub
_____________________________________________________________






Text Display 2

Program 12 displays the message taken from a TextBox. This is a very simple program and it is for the absolute beginners.

Learn about text box: 

Displaying text with print method and textbox control
             
                                                   >> DOWNLOAD

Code:
Private Sub cmdPrint_Click()
    Dim s As String
    s = txtField.Text
    Print s
End Sub
________________________________
Private Sub cmdClear_Click()
    Cls       'Form1.Cls is also correct
End Sub
_________________________________________________________




Default & Cancel key

Program 10 lets you understand the concept of 'Default' and 'Cancel' property. In this program, when you press ENTER from the keyboard, a particular message is displayed.

Learn about CommandButton: 


Default and Cancel property of form
             
                                                   >> DOWNLOAD
 

Code:
Private Sub cmdShow_Click()
    MsgBox "You have pressed the default button !", vbInformation, ""
End Sub
_________________________________________
Private Sub cmdExit_Click()
    End
End Sub
__________________________________________________________



Sum Calculator

This is a very small calculator that only adds two numbers. The two numbers are taken in Text Fields, and the result is shown in another Text Field.


Learn about I/O operations: 

This is a sample progarm that adds two numbers
            
                                                   >> DOWNLOAD

Code:
Private Sub cmdCalculate_Click()
    Dim a As Integer, b As Integer
    a = Val(txtValue1.Text)  'val function converts string 

                             'into value
    b = Val(txtValue2.Text)
    txtResult.Text = a + b
End Sub
_____________________________________
Private Sub cmdClear_Click()
    txtValue1.Text = ""
    txtValue2.Text = ""
    txtResult.Text = ""
End Sub