Microsoft Visual Basic 6 (Intrinsic Control)
Microsoft Visual Basic 6 (Intrinsic Control)
Example-01
Private Sub Text1_KeyPress(KeyAscii As Integer)
MsgBox KeyAscii
End Sub
Example-02
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii < 57 Then
MsgBox "You pressed Numeric Key. " + Chr(KeyAscii)
KeyAscii = 0
ElseIf KeyAscii >= 97 And KeyAscii <= 122 Then
MsgBox "You pressed Small character Key. " + Chr(KeyAscii)
KeyAscii = 0
ElseIf KeyAscii >= 65 And KeyAscii <= 90 Then
MsgBox "You pressed capital character Key. " + Chr(KeyAscii)
KeyAscii = 0
Else
MsgBox "Un-Know character." & KeyAscii
KeyAscii = 0
End If
End Sub
Example-01
Visual Basic Intrinsic Control
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If (Shift And vbShiftMask) Then
MsgBox "You pressed Shift Key."
ElseIf (Shift And vbAltMask) Then
MsgBox "You pressed Alt Key."
ElseIf (Shift And vbCtrlMask) Then
MsgBox "You pressed Control Key."
ElseIf KeyCode = vbKeyF2 Then
MsgBox "You pressed F2 key."
End If
End Sub
Events Description
Activate occurs when an object becomes the active window.
Deactivate occurs when an object is no longer the active window.
Initialize Occurs when an application creates an instance of a Form
Load Occurs when a form is loaded.
Unload Occurs when a form is about to be removed from the screen. When
that form is reloaded, the contents of all its controls are
reinitialized. This event is triggered by a user closing the form using
the Close command on the Control menu or an Unload/End statement.
QueryUnload Occurs before a form or application closes.
Terminate Occurs when all references to an instance of a Form are removed
from memory.
Resize Occurs when the window state of an object changes. (For example, a
form is maximized, minimized, or restored.)
Example of QueryUnload Event
Syntax
Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
End sub
The QueryUnload event syntax has these parts:
Part Description
cancel An integer. Setting this argument to any value other than 0 stops the
QueryUnload event in all loaded forms and stops the form and application
from closing.
unloadmode A value or constant indicating the cause of the QueryUnload event, as
described in Return Values.
Visual Basic Intrinsic Control
Return Values
The unloadmode argument returns the following values:
Constant Value Description
vbFormControlMenu 0 The user chose the Close command from the Control
menu on the form.
vbFormCode 1 The Unload statement is invoked from code.
vbAppWindows 2 The current Microsoft Windows operating
environment session is ending.
vbAppTaskManager 3 The Microsoft Windows Task Manager is closing the
application.
vbFormMDIForm 4 An MDI child form is closing because the MDI form
is closing.
vbFormOwner 5 A form is closing because its owner is closing.
Example-01
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = 0 Then
Cancel = 0
Else
Cancel = 1
End If
End Sub
Events Description
Change Indicates the contents of a control have changed.
Validate Occurs before the focus shifts to a (second) control that has its
CausesValidation property set to True.
Methods Description
SelText Return the selected text.
SelStart Set the position of first character.
SelLength Return or set the length of the selected text.
Example-01
Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Frame Control
A Frame control provides an identifiable grouping for controls. You can also use a Frame to
subdivide a form functionally
CommandButton Control
The command button is one of the most important controls as it is used to execute
commands.
Properties Description
Cancel Set commandbutton is the cancel button on a form.(To invoke press ESC
key)
DisablePicture Set a graphic to be display when the button is disabled.
DownPicture Set a graphic to be display when the button is down position.
Style Set the appearance of the control.
PictureBox Control
A PictureBox control can display a graphic from a bitmap, icon, or metafile.
Properties Description
AutoSize Returns or sets a value that determines whether a control is automatically
resized to display its entire contents.
Picture Sets a graphic to be displayed in a control.
Events Description
ItemCheck Occurs when a ListBox control Style property is set to 1 (checkboxes) and
an item’s checkbox in the ListBox control is selected or cleared.
Scroll Occurs when the scroll box on a ScrollBar control, or an object which
contains a scrollbar, is repositioned or scrolled horizontally or vertically.
Methods Description
AddItem To add item to the list.
RemoveItem To remove an item from the list.
Clear Remove all items from the list.
ListCount Count the number of item in the list.
List() To retrieve the item from the list according index number.
ListIndex This is the index of the selected item in the list.
Selected The value if True if the element is selected otherwise it’s False.
SelCount Return the number of selected items in a Listbox control.
Example-01
Example-01
Private Sub Dir1_Change()
File1.Pattern = "*.BMP"
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Image1.Picture = LoadPicture(File1.Path & "\" & File1.FileName)
End Sub
Events Description
Scroll Occurs when the scroll box on a ScrollBar control, or an object which
contains a scrollbar, is repositioned or scrolled horizontally or vertically.
Timer Control
A Timer control can execute code at regular intervals by causing a Timer event to occur.
Properties Description
Interval Set the number of milliseconds between calls to a timer control event.
Events Description
Timer Occurs when a preset interval for a Timer control has elapsed. The
interval's frequency is stored in the control's Interval property, which
Visual Basic Intrinsic Control
specifies the length of time in milliseconds.
Example-01
Private Sub Timer1_Timer()
Static x As Integer
If x > 5 Then
x=0
End If
Shape1.Shape = x
x=x+1
Label1.Caption = Time
End Sub
Data Control
Provides access to data stored in databases using any one of three types of Recordset
objects. The Data control enables you to move from record to record and to display and
manipulate data from the records in bound controls.
Properties Description
Connect Define the source of database.
DatabaseName Set the name and location of source database.
RecordSource Set the Table name or SQL statement.
Properties Description
Datasource Set the data control which is bound to control.
DataField Set a field in the current record which is binds a control.
Menu Control
A Menu control displays a custom menu for your application. A menu can include commands,
submenus, and separator bars. Each menu you create can have up to four levels of submenus.