VB6 0
VB6 0
Presented by-
Sri Jahnab Kr. Deka
1
How to open a Project?
2
How to open a Project-2
3
How to write codes in an event
4
Comments line in VB
How to write comments in VB
' This is a comment
Some important data types in VB
String
Double
Integer
Date
How to declare variables
Implicit
Total = Total + 10
Explicit
Dim Total as double
Total= Total + 10
5
Scope of a Variable
The term Scope refers to whether the variable is available outside the procedure in which it
appears. The scope is procedure-level or module-level.
A variable declared with Dim at the beginning of a procedure is only available in that
procedure. When the procedure ends, the variable disappears. Consider the following example:
Option Explicit
Dim Total2 As Integer
Private Sub Command1_Click ()
Dim Total1 As Integer
Static Total3 As Integer
Total1 = Total1 + 1
Total2 = Total2 + 1
Total3 = Total3 + 1
End Sub
Private Sub Command2_Click ()
Dim Total1 As Integer
Total1 = Total1 + 1
Total2 = Total2 + 1
Total3 = Total3 + 1
End Sub
6
What are different properties of a
Text Box
7
Different controls of a Text Box
Name prefix is as txt, e. g. txtName
E.g.
Text1.BackColor = vbRed
Text1.FontSize = 20
Text1.Alignment = 2
Text1.ForeColor = vbYellow
Text1.BorderStyle = 0
Text1.FontBold = True
Text1.tooltiptext=“enter something”
Text1.text=Text1
8
Multi line property of Text boxes
Select the multi line
property as one of the
following:
True
false
Select the scroll bar option
Horizontal
Vertical
None
Both
9
Different controls of a label box
Name prefix is as lbl, e. g. lblName
E.g.
Label1.BackColor = vbRed
Label1.FontSize = 20
Label1.Alignment = 2
Label1.ForeColor = vbYellow
Label1.BorderStyle = 0
Label1.FontBold = True
Label1.ToolTipText = "enter
Something"
Label1.Caption = "HI"
10
Frame Control
Frame1.BackColor = vbRed
Frame1.FontSize = 20
Frame1.FontBold = True
Frame1.BorderStyle = 1
Frame1.Caption = "Hello"
Frame1.ToolTipText = "enter
Something"
11
Command button Control
Private Sub Command1_Click()
MsgBox "You have Clicked Submit
button", vbInformation
End Sub
12
Controls of Check boxes
Private Sub Check1_Click()
MsgBox "You have Clicked Assam"
End Sub
13
Controls of Option Button
15
List Box Control
Private Sub cmdAddNew_Click()
List1.AddItem Text1.Text
Text1.Text = ""
End Sub
16
IF-Else Condition
Private Sub cmdAdd_Click()
If txtFirstNumber = “ “ Then
MsgBox "Please Enter First Number"
txtFirstNumber.SetFocus
ElseIf txtNumberTwo = “ “ Then
MsgBox "Please Enter Second Number"
txtNumberTwo.SetFocus
ElseIf IsNumeric(txtFirstNumber) = False Then
MsgBox "Please Enter Numberic Value"
txtFirstNumber.SetFocus
ElseIf IsNumeric(txtNumberTwo) = False Then
MsgBox "Please Enter Numberic Value"
txtNumberTwo.SetFocus
Else
lblResult = Val(txtFirstNumber) + Val(txtNumberTwo)
End If
End Sub
18
DO…..LOOP
Used to execute a block of statements an
unspecified number of times.
Do While condition
statements
Loop
First, the condition is tested; if condition is True,
then the statements are executed. When it gets to
the Loop it goes back to the Do and tests condition
again. If condition is False on the first pass, the
statements are never executed.
Dim i, j As Integer
Private Sub Command1_Click()
i = InputBox("Enter the limit", "DO-WHILE-LOOP", 5)
j=1
Do While j <= i
Form1.Print j;
j=j+1
Loop
End Sub 19
WHILE….WEND
Used to execute a block of statements an
unspecified number of times.
While condition
statements
Wend
First, the condition is tested; if condition is True,
then the statements are executed. When it gets to
the Loop it goes back to the Do and tests condition
again. If condition is False on the first pass, the
statements are never executed.
Dim i, j As Integer
Private Sub Command1_Click()
i = InputBox ("Enter the limit", "DO-WHILE-LOOP", 5)
j=1
While j <= i
Form1.Print j;
j=j+1
Wend
End Sub 20
FOR….NET
21
Function procedure and Sub
Procedure in VB
Difference between Function & Procedure is
A procedure is a set of code that does the work but does not return a value whereas a
function accepts parameters and does the calculation and does return a value back.
How to write Function Procedure and Sub Procedure in Visual Basic
22
How to Pass Array in a
Private Sub Command1_Click() Function
Dim x(3) As Integer 'Declare a Static Integer Array of 4 elements
x(0) = 10
x(1) = 20
x(2) = 30
x(3) = 40
Call AcceptArray(x) 'Call the procedure and pass the Array
End Sub
23
How to use Message Box
Used for displaying
messages
Prompt
Symbol
Button
title
24
How to use Input Box?
Used for taking inputs
from users
Prompt
Title
Default
X-position
Y-position
25
Horizontal/ Vertical Scroll Bar
Private Sub Form_Load()
HScroll1.Value = 0
HScroll1.Min = 0
HScroll1.Max = 100
VScroll1.Value = 0
VScroll1.Max = 100
VScroll1.Min = 0
Label1.Caption = HScroll1.Value
End Sub
26
How to include add ins and
Libraries
27
How to use the Timer?
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
28
How to use Month Viewer
Private Sub Form_Load()
MonthView1.BackColor = vbGreen
MonthView1.Appearance = ccFlat
MonthView1.ForeColor = vbRed
End Sub
29
How to use Date Picker
30
How to Create Manus
31
How to use Manus
Private Sub mnDisplay_Click()
MsgBox "Hello, You have Clicked
Display"
End Sub
32
How to use Common Dialog
Control
Private Sub mnDisplay_Click()
On Error GoTo err:
CommonDialog1.Action = 3
'display color dialog box
Form2.BackColor =
CommonDialog1.Color
Exit Sub
err:
MsgBox "Dialog is canceled"
End Sub
33
How to Use MS-Flex Grid
Private Sub Command1_Click()
MSFlexGrid1.TextMatrix(9, 2) =
Val(MSFlexGrid1.TextMatrix(1, 2)) +
Val(MSFlexGrid1.TextMatrix(2, 2)) +
Val(MSFlexGrid1.TextMatrix(3, 2))
End Sub
34