2. 2CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Course Outline
Introduction to VB
Analyzing VB Programs
Controls & Properties
Examining Labels, Buttons & Text Boxes
Putting Code into Visual Basic
Message & Input Boxes
Making Decisions
VB Looping
List Boxes & Data Lists
Additional Controls
Modular Programming
Built-In Functions
VB Database Basics
Menus & VB
The Graphics Image Controls
Toolbars & More Graphics
Database Connectivity & Programming
3. 3CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Introduction to Visual Basic 6.0
What is Visual Basic?
Creates Graphic User Interface (GUI)
Creates applications for the Microsoft Windows OS
Major components:
1. Forms
2. Controls
3. Commands
4. Objects
4. 4CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
History of Visual Basic
• Alan Cooper developed Visual Basic in 1988 and
sold to Microsoft
• VB1 Debuts at Windows World in March 20,1991
• VB2 Debuts in November 1992
• VB3 Debuts in June 1993
• VB4 Debuts in October 1996
• VB5 Debuts in April 1997
• VB6 Debuts in October 1998
5. 5CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Introduction to Visual Basic 6.0
What programming language is Visual Basic
based on?
BASIC (stands for Beginner’s All Purpose
Symbolic Introduction Code)
6. 6CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Starting Visual Basic 6.0
• Click on Start
• Select Programs
• Select Microsoft Visual Studio 6.0
• Click on Microsoft Visual Basic 6.0
• Click on Open
8. 8CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Introduction to Visual Basic 6.0
What is a Form Window?
The form window holds the application’s
form background and all its user controls,
such as command buttons.
What is a Toolbox?
The toolbox contains the controls that you
place on the Form Window. All the controls
appear on the toolbox.
11. 11CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
• Enter the following code
Label5= val(text1) + val(text2)
To display answer Number 2
Number 1
Value
Writing the program
15. 15CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Controls in the Toolbox
• Label
– A label control is used to display text that a user can’t
change directly.
• Textbox
– A textbox control is used to input data from the user at run
time.
• Command button
– A command button is used to perform an event at run time.
25. 25CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
IF …..Then…..Else
Statement
• If...Then...Else statement is used for
controlling the program flow.
• To control the VB program flow, we
can use various conditional operators
and logical operators.
26. 26CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Conditional Operators
Operator Meaning
= Equal to
> Greater than
< Less Than
< > Not Equal to
• The conditional operators compares data
values and then decide what action to take.
27. 27CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Examples
A=10, B=15
Operations Result
Is A=B ?
FALSE / NO
Is A>B ?
FALSE / NO
Is A<B ?
TRUE / YES
Is A< >B ?
TRUE / YES
29. 29CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Logical Operators
OR: One side or other must be true
Side A Side B Result
TRUE TRUE ?
TRUE
FALSE TRUE ?
TRUE
FALSE FALSE ?
FALSE
34. 34CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Coding..
• Double Click on OK
Private Sub Command1_Click()
If Text1 > 8 Then
MsgBox (“You are late !!”)
Else
MsgBox (“You are not late !!”)
End If
End Sub
36. 36CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option1
Private Sub Option1_Click()
If Option1.Enabled = True Then
Form1.BackColor = vbRed
End If
End Sub
37. 37CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option2
Private Sub Option2_Click()
If Option2.Enabled = True Then
Form1.BackColor = vbBlue
End If
End Sub
38. 38CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option3
Private Sub Option3_Click()
If Option3.Enabled = True Then
Form1.BackColor = vbWhite
End If
End Sub
39. 39CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option4
Private Sub Option4_Click()
If Option4.Enabled = True Then
Form1.BackColor = vbBlack
End If
End Sub
40. 40CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option5
Private Sub Option5_Click()
If Option5.Enabled = True Then
Form1.BackColor = vbYellow
End If
End Sub
41. 41CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option6
Private Sub Option6_Click()
If Option6.Enabled = True Then
Form1.BackColor = vbGreen
End If
End Sub
43. 43CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option1
Private Sub Option1_Click()
If Option1.Enabled = True Then
Label1.FontBold = True
End If
End Sub
44. 44CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option2
Private Sub Option2_Click()
If Option2.Enabled = True Then
Label1.FontItalic = True
End If
End Sub
45. 45CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option3
Private Sub Option3_Click()
If Option3.Enabled = True Then
Label1.FontUnderline = True
End If
End Sub
46. 46CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option4
Private Sub Option4_Click()
If Option4.Enabled = True Then
Label1.FontSize = 10
End If
End Sub
47. 47CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option5
Private Sub Option5_Click()
If Option5.Enabled = True Then
Label1.FontSize = 20
End If
End Sub
48. 48CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Option6
Private Sub Option6_Click()
If Option6.Enabled = True Then
Label1.FontSize = 30
End If
End Sub
49. 49CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Visual Basic Fundamentals
• Numeric constants: integer, long integers, single -
precision real (or floating point), double-precision real (or
floating point)
• String constants
• Variables
– Name must begin with a letter, letters and numbers
can be included, as well as underline character ( _ )
– Data-typing characters ( %, &, !, #, $) are not
permitted
– Maximum length of name = 255characters
50. 50CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Data types and data declaration
• Data types supported: Integer, Long,
Single, Double, String, Boolean, Byte,
Currency, Date
• Data declaration uses the Dim statement
Dim variable_name_1 As data_type_1,
variable_name_2 As data_type_2, etc.
Example:
Dim firstname as string
51. 51CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Branching and Looping
• Relational operators and logical expressions
– Relational operators: = , < > , < , <= , > , >=
– Logical expressions, e.g., a > b, c = d + 2, x >= y,
can be either true or false
52. 52CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
If ..Then..Else..Endif Statement
If logical_expression Then
. . . . .
executable statements
. . . . .
Else
. . . . .
executable statements
. . . . .
End If
53. 53CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Select Case Statement
Select Case expression
Case value1
executable statements
Case value2
executable statements
. . . . . . .
Case Else
executable statements
End Select
59. 59CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
VB Control Fundamentals
• Control tool categories
Displaying Text Selecting Among Alternatives
Label Check Box
Text Box Option Button
List Box Frame
Combo Box List Box
60. 60CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
VB Control Fundamentals
• Control tool categories
Displaying Graphics Viewing Windows
Image Box Frame
Picture Box Horizontal Scroll Bar
Frame Vertical Scroll Bar
61. 61CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
VB Control Fundamentals
• Control tool categories
Managing Files Accessing Existing Data
File List Box Data
Drive List Box
Directory List Box
62. 62CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
VB Control Fundamentals
• Control tool categories
Initiating Events Linking with Other Objects
Command Button OLE
Executing Timed Events
Timer
63. 63CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
MsgBox
• Message boxes are used when you want to ask the
user a question or display an error message(s) and
advise the user
• There are six types of message boxes -
– vbOKonly
– vbOKCancel
– vbAbortRetryIgnore
– vbYesNoCancel
– vbYesNo
– vbRetryCancel
64. 64CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
MsgBox
• Syntax
Msgbox “TEXT”, VALUE, “TITLE”
• Example 1
Msgbox “Sorry !!”, vbcritical, “Error”
• Example 2
Msgbox “Correct Password”, vbinformation, “Check”
76. 76CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on form1
Private Sub Form_Load()
List1.AddItem “……”
List1.AddItem “Red”
List1.AddItem “Yellow”
List1.AddItem “Green”
List1.AddItem “Blue”
End Sub
77. 77CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on List1
Private Sub List1_Click()
If List1 = “Red” Then
Form1.BackColor = vbRed
ElseIf List1 = “Yellow” Then
Form1.BackColor = vbYellow
ElseIf List1 = “Green” Then
Form1.BackColor = vbGreen
ElseIf List1 = “Blue” Then
Form1.BackColor = vbBlue
Else
Form1.BackColor = vbWhite
End If
End Sub
80. 80CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code• Double click on Command Button Grade
Private Sub Command2_Click()
If Val(Text5) >= 80 And Val(Text5) <= 100 Then
Text6 = “A”
ElseIf Val(Text5) >= 60 And Val(Text5) <= 79 Then
Text6 = “B”
ElseIf Val(Text5) >= 40 And Val(Text5) <= 59 Then
Text6 = “C”
ElseIf Val(Text5) >= 0 And Val(Text5) <= 39Then
Text6 = “F”
Else
Text6 = “ ”
MsgBox “Error!!”
End If
End Sub
81. 81CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button Clear
Private Sub Command3_Click()
Text1 = Clear
Text2 = Clear
Text3 = Clear
Text4 = Clear
Text5 = Clear
Text6 = Clear
End Sub
84. 84CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Double click on confirm
Private Sub Command1_Click()
If Option1 = True Then
frmoneway.Show
frmmain.Hide
ElseIf Option2 = True Then
frmroundtrip.Show
frmmain.Hide
Else
MsgBox "Please select a trip"
End If
End Sub
87. 87CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Double click on frmoneway
Private Sub Form_Load()
Label2 = Date
Label3 = Time
Combo1.AddItem “F101”
Combo1.AddItem “F102”
Combo1.AddItem “F103”
End Sub
88. 88CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Double click on Combo1_Click
Private Sub Combo1_Click()
If Combo1 = “F101” Then
Text1 = “Bangkok”
Text2 = “Chiangmai”
Text3 = 1000
Text4 = 200
Text5 = Val(Text3) + Val(Text4)
ElseIf Combo1 = “F102” Then
Text1 = “Chiangmai”
Text2 = “Bangkok”
Text3 = 1000
Text4 = 200
Text5 = Val(Text3) + Val(Text4)
89. 89CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Double click on Combo1_Click
ElseIf Combo1 = “F103” Then
Text1 = “Bangkok”
Text2 = “Phuket”
Text3 = 1500
Text4 = 200
Text5 = Val(Text3) + Val(Text4)
Else
MsgBox "Please select your flight no"
End If
End Sub
95. 95CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Solution
• Double click on Command1 Grade
Private Sub Command1_Click()
If Val(Text2) >= 90 And Val(Text2) <= 100 Then
Text3 = “A+”
ElseIf Val(Text2) >= 80 And Val(Text2) <= 89 Then
Text3 = “A”
ElseIf Val(Text2) >= 70 And Val(Text2) <=79 Then
Text3 = “B+”
ElseIf Val(Text2) >= 60 And Val(Text2) <= 69 Then
Text3 = “B”
ElseIf Val(Text2) >= 50 And Val(Text2) <= 59 Then
Text3 = “C+”
ElseIf Val(Text2) >= 40 And Val(Text2) <= 49 Then
Text3 = “C”
ElseIf Val(Text2) >= 0 And Val(Text2) <= 39 Then
Text3 = “F”
Else
Text3 = “Error!!”
End If
End Sub
98. 98CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code for Timer1
• Double click on Timer1
Private Sub Timer1_Timer()
If Label1.Visible = True Then
Label1.Visible = False
Else
Label1.Visible = True
End If
End Sub
102. 102CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Solution
• Double click on Command1 GO
If Val(Text1) > Val(Text2) Then
MsgBox “B is smaller, B= ” + Text2
Else
MsgBox “A is smaller, A= ” + Text1
End If
104. 104CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button1 Login
Private Sub Command1_Click()
Dim password As String
password = “lcct”
If Text1 = password Then
password = MsgBox(“You have passsed security!!”, vbOKOnly +
vbExclamation, “Access Granted”)
Else
password = MsgBox (“Incorrect Password!!”, vbRetryCancel +
vbCritical, “Access Denied”)
If password = vbRetry Then
Text1 = ""
Text1.SetFocus
End If
End If
End Sub
105. 105CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Select Case
• The Select Case structure tests whether the value
of an expression falls within predetermined ranges.
• Syntax
Select Case expression
Case testlist
{instructions}
Case testlist
{instructions}
:
Case else
{instructions}
End Select
107. 107CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
• Double click on
Dim age as Integer
age=text1
Select case age
case 1 to 12
Msgbox (“Child”)
case 13 to 19
Msgbox (“Teenager”)
case is > 19
Msgbox (“Adult”)
case else
Msgbox (“Impossible”)
End select
OK
109. 109CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Program Explanation
• Use Select Case to do the program
• When the user enters blank string
– Display Message box “Null / Blank String”
• When the user enters a or e or I or o or u
– Display Message box “Vowel”
• When the user enters a to z
– Display Message box “Consonant”
• When the user enters 0 to 9
– Display Message box “Numeric Digit”
• When the user enters any other characters
such as $ or @ or *
– Display Message box “Special Character”
110. 110CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
• Double click on
Dim str As String
str = Text1
Select Case Left(str, 1)
Case “”
MsgBox (“Null String”)
Case “A”, “E”, “I”, “O”, “U”, “a”, “e”, “i”, “o”, “u”
MsgBox (“Vowel”)
Case “A” To “Z”, “a” To “z”
MsgBox “Consonant”
Case “0” To “9”
MsgBox “Numeric Digit”
Case Else
MsgBox “Special Character”
End Select
OK
114. 114CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Form
Private Sub Form_Load()
Combo1.AddItem "English"
Combo1.AddItem "Thai"
Combo1.AddItem "Japanese"
Combo1.AddItem "Chinese"
Combo1.AddItem "India"
End Sub
115. 115CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Combo1
Private Sub Combo1_Click()
Select Case Combo1
Case "English"
Text1 = "Hello"
Case "Thai"
Text1 = "Suwadee"
Case "Japanese"
Text1 = "Konichiwa"
Case "Chinese"
Text1 = "Nihaw"
Case "India"
Text1 = "Namaste"
End Select
End Sub
117. 117CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
Private Sub Option1_Click()
Label1.FontBold = True
End Sub
Private Sub Option2_Click()
Label1.FontBold = False
End Sub
Private Sub Option3_Click()
Label1.FontItalic = True
End Sub
Private Sub Option4_Click()
Label1.FontItalic = False
End Sub
Private Sub Option5_Click()
Label1.FontUnderline = True
End Sub
Private Sub Option6_Click()
Label1.FontUnderline = False
End Sub
118. 118CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
Private Sub Option7_Click()
Label1.FontSize = 10
End Sub
Private Sub Option8_Click()
Label1.FontSize = 15
End Sub
Private Sub Option9_Click()
Label1.FontSize = 20
End Sub
119. 119CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
Private Sub Option10_Click()
Label1.ForeColor = vbBlue
End Sub
Private Sub Option11_Click()
Label1.ForeColor = vbRed
End Sub
Private Sub Option12_Click()
Label1.ForeColor = vbYellow
End Sub
Private Sub Option13_Click()
Label1.ForeColor = vbGreen
End Sub
121. 121CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Score, Command Button1
Private Sub Command1_Click()
Dim answer As Integer
If Option2.Value = True Then
answer = answer + 1
End If
If Option4.Value = True Then
answer = answer + 1
End If
If Option8.Value = True Then
answer = answer + 1
End If
If answer = 3Then
MsgBox “You scored 3”
ElseIf answer = 2 Then
MsgBox “You scored 2”
ElseIf answer = 1 Then
MsgBox “You scored 1”
ElseIf answer = 0 Then
MsgBox “You scored 0”
End If
End Sub
123. 123CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button 1 Add Number
Private Sub Command1_Click()
Combo1.AddItem Text1
Text1 = ""
Text1.SetFocus
End Sub
• Double click on Command Button 2 Count
Private Sub Command2_Click()
MsgBox “Total items = ” & Combo1.ListCount
End Sub
124. 124CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button 3 Maximum
Private Sub Command3_Click()
Dim Max As Integer
Dim i As Integer
Max = 0
For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) > Max Then
Max = Combo1.List(i)
End If
Next i
MsgBox “Maximum Number = ” & Max
End Sub
125. 125CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button 4 Minimum
Private Sub Command4_Click()
Dim Min As Integer
Dim i As Integer
Min = 100
For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) < Min Then
Min = Combo1.List(i)
End If
Next i
MsgBox “Minimum Number = ” & Min
End Sub
126. 126CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button 5 Sum
Private Sub Command5_Click()
Dim sum, i As Integer
For i = 0 To Combo1.ListCount - 1
sum = sum + Val(Combo1.List(i))
Next i
MsgBox “Sum=” & sum
End Sub
127. 127CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command Button 6 Average
Private Sub Command6_Click()
Dim average, sum, i As Integer
For i = 0 To Combo1.ListCount - 1
sum = sum + Val(Combo1.List(i))
Next i
average = Val(sum) / Combo1.ListCount
MsgBox “Average = ” & average
End Sub
128. 128CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Designing a Menu Bar
• What is a Menu Bar ?
– A menu bar is used to display a list of items from where
an user can select any one item.
129. 129CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Example: Menu Bar
• Click on the Menu Editor in the Tool Bar
• In the caption, type File
• In the name, type mnufile
• Click OK
• Run
130. 130CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Menu Editor
Menu Caption
Menu Name
Menu Shortcut Key
To add new menu
To insert new menu
Directions
(Left, Right, Up, Down)
To delete menu
131. 131CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Designing a Sub_Menu
• Click on Menu Editor in Toolbar.
• In Caption, type File
• In Name, type mnuFile
• Click on Next
• Click on Right Arrow Button
• In Caption, type Open
• In Name, type mnuOpen
• In ShortCut Key, Ctrl+O
• Click on Next
• In Caption, type -
• In Name, type mnublank1
• Click on Next
• In Caption, type New
• In Name, type mnuNew
• In ShortCut Key, Ctrl+N
132. 132CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Designing a Multiple menu
• Click on Menu Editor in Toolbar.
• In Caption, type File
• In Name, type mnuFile
• Click on Next
• Click on Right Arrow Button
• In Caption, type Open
• In Name, type mnuOpen
• In ShortCut Key, Ctrl+O
• Click on Next
• In Caption, type -
• In Name, type mnublank1
• Click on Next
• In Caption, type New
• In Name, type mnuNew
• In ShortCut Key, Ctrl+N
133. 133CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Designing the EDIT Menu
• Click on Menu Editor in Toolbar.
• Click on Left Arrow Button
• In Caption, type Edit
• In Name, type mnuEdit
• Click on Next
• Click on Right Arrow Button
• In Caption, type Copy
• In Name, type mnuCopy
• In ShortCut Key, Ctrl+C
• Click on Next
• In Caption, type -
• In Name, type mnublank2
• Click on Next
• In Caption, type Cut
• In Name, type mnuCut
• In ShortCut Key,
Ctrl+X
• Click on Next
• In Caption, type -
• In Name, type mnublank3
• Click on Next
• In Caption, type Paste
• In Name, type mnuPaste
• In ShortCut Key,
Ctrl+V
134. 134CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Using the Data Control to
Interact with Databases
• The VB Data Control is used to attach an
existing database, providing a link
between your application and your data.
• Various controls - such as
– labels
– images
– text boxes
can be connected to the data control.
135. 135CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Creating a Database Application
Step 1
• Create a table in MS-Access
• Save as, student
• Enter any five records
Field Name DataType FieldSize
Code Number Integer
Name Text 50
Primary
Key
137. 137CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Creating a Database Application
Step 3
Connecting the Data Control
• Select Data1
• In the property window,
• Select Database Name - Student
• Select Record Source (Table Name) - Student
• Select Text1
• In the property window,
• Select Data Source – Data1
• Select Data Field - Code
• Select Text2
• In the property window,
• Select Data Source – Data1
• Select Data Field - Name
138. 138CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Create a table in MS-Access
Save Database as : grade
Save Table as: grade
Field name Fieldtype
S_Code Number
Name Text
G_Vb Text
G_Datastructure Text
G_P_A Text
144. 144CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Designing Status bar
• Right click on the Toolbox
• Select Microsoft Windows Common Controls 6.0
• Click Ok
• Double click on the status bar
• Select the status bar
• Right click
• Click on Properties
• Select Panels
147. 147CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Writing Code
• Double click on form
Private Sub Form_Load()
StatusBar1.Panels(1) = Date
StatusBar1.Panels(2) = Time
End Sub
148. 148CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Quiz Project
• Start MS-ACCESS 97
• Save Project as, Quiz
• Save Table 1 as, Computer_Quiz
• Save Table 2 as, Score_Quiz
149. 149CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Table 1 - Computer_Quiz
FieldName DataType
No Autonumber
Question Memo
Option1 Text
Option2 Text
Option3 Text
Answer Number
152. 152CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double click on Command1 (SignIn)
Private Sub Command1_Click()
If Text1 = “lcct” And Text2 = “lcct” Then
Unload Me
Form2.Show
Else
a = MsgBox(“Please Try Again”, vbCritical, vbOK)
Text1 = ""
Text2 = ""
Text1.SetFocus
End If
End Sub
154. 154CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Connect Data1 (On-line Computer Test)
• Select Data1
• In the property of Data1,
• Database name Quiz
• Recordsource Computer_Quiz
155. 155CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Code
• Double Click on Command 1
Private Sub Command1_Click()
If Data1.Recordset(“Answer”) = Val(Text1) Then
MsgBox “Congratulations!! Correct”
Label9 = Label9 + 1
Data1.Recordset.MoveNext
Else
MsgBox “Sorry!! Wrong”
Data1.Recordset.MoveNext
End If
Text1 = ""
Text1.SetFocus
156. 156CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
Data2.Recordset.AddNew
Data2.Recordset(“Name”) = Text2
Data2.Recordset(“Score”) = Label9
Data2.Recordset.Update
Data2.Refresh
MsgBox “Thankyou for the test”
End
End If
EndSub
158. 158CopyrightMr.Anjan Mahanta LCCTInternational Studies Program
Select Case Button.Index
Case 1
Form1.BackColor = vbBlack
Case 2
Form1.BackColor = vbBlue
Case 3
Form1.BackColor = vbRed
Case 4
Form1.BackColor = vbWhite
Case 5
Form1.BackColor = vbYellow
End Select