Download presentation
Presentation is loading. Please wait.
1
VISUAL BASIC 6.0 Designed by Mrinal Kanti Nath
2
INTRODUCTION Visual Basic is an object-oriented programming development system for creating applications that run under any of the Microsoft Windows environments. It has the following two major components: 1. An extensive collection of prewritten tools, called controls. 2. A complete set of program commands, derived from Microsoft’s implementation of the classical Basic programming language. Designed by Mrinal Kanti Nath
3
EVENT DRIVEN PARADIGM Each feature included within the program is activated only when the user responds to a corresponding object within the user interface. The program’s response to an action taken by the user is referred to as an event. The group of Basic commands that brings about this response is called an event procedure. Designed by Mrinal Kanti Nath
4
OBJECT RELATED CONCEPTS
FORMS: In VB, a window is called a form. Each form includes a title bar at the top & it also include a menu bar, a status bar, one or more toolbars, slide bars, etc. CONTROLS: The icons with which the user interacts are called controls. Commonly used controls include command buttons, option buttons, check boxes, labels, text boxes, picture boxes and menus. OBJECTS: Forms and controls are referred to collectively as objects. Designed by Mrinal Kanti Nath
5
OBJECT RELATED CONCEPTS CONTD..
PROPERTIES: Objects include properties that generally define their appearance or behavior. For example, the name, caption, height, width, background color, location etc.. METHODS: Some objects also include special program statements called methods. For example, show is a method that can be used with a hidden form to make it visible. Designed by Mrinal Kanti Nath
6
VB PROGRAM COMPONENTS In VB, a program is referred to as a project.
Every VB project consists of at least two separate files – a project file (.vbp) and a form file (.frm) Some projects include multiple form files and other types of files, such as class module (.cls) files, standard module (bas) files, resource (.res) files, and ActiveX control (.ocx) files. Designed by Mrinal Kanti Nath
7
Designed by Mrinal Kanti Nath
8
Designed by Mrinal Kanti Nath
9
Designed by Mrinal Kanti Nath
10
Code Editor Window Designed by Mrinal Kanti Nath
11
Example: Area of a Circle
Designed by Mrinal Kanti Nath
12
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
13
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
14
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
15
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
16
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
17
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
18
Example: Area of a Circle Contd..
Designed by Mrinal Kanti Nath
19
Data Types and Data Declaration
Integer Long (Long Integer) Single Double String E.G.- Dim variable name As data type Dim Area As Single Dim StudentName As String Designed by Mrinal Kanti Nath
20
Const TaxRate As Single = 0.28
Named Constant Similar to variables. But, variables can be reassigned different values within a program, whereas named constants remain unchanged throughout a program. E.g.- Const TaxRate As Single = 0.28 Designed by Mrinal Kanti Nath
21
User Defined Data Types
Type Customer CustomerName As String AcctNo As Integer Balance As Single End Type Once the data type has been defined, we can declare one or more variables of this data type, as follows. Dim OldCustomer As Customer, NewCustomer As Customer Designed by Mrinal Kanti Nath
22
Arithmetic Operators The standard arithmetic operators are
Addition: + (plus sign) Subtraction: − (minus sign) Multiplication: * (asterisk) Division: / (slash) Exponentiation: ^ (caret, or upward-pointing arrow) Integer division: \ (backward slash) Integer remainder: Mod Designed by Mrinal Kanti Nath
23
Relational Operators Equal: = Not equal: <> Less than: <
Less than or equal to: <= Greater than: > Greater than or equal to: >= Designed by Mrinal Kanti Nath
24
Logical Operators And will result in a condition that is true if both expressions are true. Or will result in a condition that is true if either expression is true, or if they are both true Xor will result in a condition that is true only if one of the expressions is true and the other is false. Not is used to reverse (negate) the value of a logical expression. Eqv will result in a condition that is true if both expressions have the same logical value Imp will always result in a true condition unless the first expression is true and the second is false. Designed by Mrinal Kanti Nath
25
Hierarchy Of Operations
Exponentiation ^ Negation (i.e., preceding a numeric −quantity with a minus sign) Multiplication and division * / Integer division \ Integer remainder Mod Addition and subtraction + − Relationals = <> < <= > >= Logical Not Not Logical And And Logical Or Or Logical Xor Xor Logical Eqv Eqv Logical Imp Imp Designed by Mrinal Kanti Nath
26
Inserting Parentheses
[ 2(a + b)2 + (3c)2 ] m / (n+1) A Visual Basic expression corresponding to this algebraic term is (2 * (a + b) ^ 2 + (3 * c) ^ 2) ^ (m / (n + 1)) ((2 * ((a + b) ^ 2)) + ((3 * c) ^ 2)) ^ (m / (n + 1)) Both are correct. The arithmetic expression −x ^ n is equivalent to −(x ^ n) or −1 * (x ^ n) Designed by Mrinal Kanti Nath
27
String Concatenation Str1 = "TEN" Str2 = "THOUSAND”
Str1 & " " & str2 & " DOLLARS” Str1 + " " + str2 + " DOLLARS” Both will print: TEN THOUSAND DOLLARS Designed by Mrinal Kanti Nath
28
Designed by Mrinal Kanti Nath
29
Print Statement Print statement is used to display information within the currently active form, beginning in the upper left corner. Dim Student As String, X As Integer, C1 As Single, C2 As Single Student = "Aaron" X = 39 C1 = 7 C2 = 11 Print "Name:", Student, X, (C1 + C2) / 2 Designed by Mrinal Kanti Nath
30
If-Then Syntax: If logical expression Then executable statement End If
Example: If income <= Then tax = 0.2 * pay net = pay - tax Designed by Mrinal Kanti Nath
31
If-Then-Else Syatax: If logical expression Then executable statements
End If Example: If (status = "single") Then tax = 0.2 * pay tax = 0.14 * pay Designed by Mrinal Kanti Nath
32
If-Then-Else If logical expression 1 Then executable statements ElseIf logical expression 2 Then repeated ElseIf clauses Else End If Designed by Mrinal Kanti Nath
33
Case structure Syntax Select Case expression Case value1 executable statements Case value Case Else End Select Designed by Mrinal Kanti Nath
34
Case Structure Example
Dim x, z, n As Integer Select Case n Case 1 z = x Case 2 z = x ^ 2 Case 3 z = x ^ 3 Case Else MsgBox("ERROR - Please try again") End Select Designed by Mrinal Kanti Nath
35
For- Next Syntax For index = value1 To value2 executable statements
Next index Example: sum = 0 For i = 1 To 10 sum = sum + i Next i Designed by Mrinal Kanti Nath
36
For- Next Contd.. For index = value1 To value2 Step value3 executable statements Next index sum = 0 For count = 2.5 To -1 Step -0.5 sum = sum + count Next count count will take on the values 2.5, 2.0, 1.5, . . ., 0.0, -0.5, Hence, the final value of sum will be 6.0 (because – 0.5 – 1.0 = 6.0). Designed by Mrinal Kanti Nath
37
Do Loop First form: Do While logical expression executable statements
Second form: Do Until logical expression Designed by Mrinal Kanti Nath
38
Do Loop Contd.. Third form: Do executable statements
Loop While logical expression Fourth form: Loop Until logical expression Designed by Mrinal Kanti Nath
39
Do Loop Contd.. First form continues to loop as long as the logical expression is true Second form continues to loop as long as the logical expression is not true (until the logical expression becomes true). Third form continues to loop as long as the logical expression is true. Fourth form continues to loop as long as the logical expression is not true. Designed by Mrinal Kanti Nath
40
While-Wend While logical expression executable statements Wend
Example: sum = 0 count = 1 While count <= 10 sum = sum + count count = count + 1 Designed by Mrinal Kanti Nath
41
Stop Statement Used to terminate the execution at any point in the program. The statement consists simply of the keyword Stop May appear anywhere in a Visual Basic program except at the very end. Multiple Stop statements may appear in the same program, as dictated by the program logic. Designed by Mrinal Kanti Nath
42
Designed by Mrinal Kanti Nath
43
Designed by Mrinal Kanti Nath
44
Thank You Designed by Mrinal Kanti Nath
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.