SIMPLE PROGRAM 1

Your first VB program

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

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

Example of MouseMove

Example of MouseMove event
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

sample program to show MouseDown & MouseUp events          
              
 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                
_______________________________________________________________   

General Declaration

Variable declaration in general declaration section
             
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 program uses static variable to display the number of clicks
             
Code:
Private Sub cmdClick_Click()
    Static n As Integer
    n = n + 1
    Print n
End Sub

Text Dispay 1

The program shows message in text box
             
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

Displaying text with print method and textbox control
             
 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

Default and Cancel property of form
             
 Code:
Private Sub cmdShow_Click()
    MsgBox "You have pressed the default button !", vbInformation, ""
End Sub
_________________________________________
Private Sub cmdExit_Click()
    End
End Sub
Set propertiesThe sample program showing how to set properties
             
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