0% found this document useful (0 votes)
54 views10 pages

Chapter 12 - Elements of Visual Basic Programming - Act Malappuram

The document summarizes the key elements of Visual Basic programming, including data types, variables, constants, and operators. It describes common data types like string, integer, currency, and date that are used to store different types of data. It also explains how variables are used as named locations to store data, and how constants are values assigned to variables that cannot change. Finally, it provides examples of common arithmetic, relational, and logical operators used to perform operations on data stored in variables and constants.

Uploaded by

MasudRana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
54 views10 pages

Chapter 12 - Elements of Visual Basic Programming - Act Malappuram

The document summarizes the key elements of Visual Basic programming, including data types, variables, constants, and operators. It describes common data types like string, integer, currency, and date that are used to store different types of data. It also explains how variables are used as named locations to store data, and how constants are values assigned to variables that cannot change. Finally, it provides examples of common arithmetic, relational, and logical operators used to perform operations on data stored in variables and constants.

Uploaded by

MasudRana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

Search this site

act malappuram
Syllabus home > Syllabus > Theory Notes > +1 Commerce Theory Notes Titles >
Syllabus
Chapter 12: Elements of Visual Basic Programming
Year Plan
Year Plan

Theory Notes Chapter 12. Elements of VB Programming


Theory Notes
Data types
Practical Notes
Practical Notes Data types are used to store and identify the type of data that are
Model Questions supplied through the variables to a program.
Model Questions
They are, String, Integer, Long, Single, Double, Currency, Date,
Previous QP
Boolean and Variant.
Previous QP

Usefull Links Data Usage Storage size Range


IT Links type/
MM Presentations Key
MM Presentations words
Videos
Videos
String To store Group of 10 bytes + 0-2billion
characters enclosed in
Images
double quotes called string length
Images
string
Animations
Animations Integer To represent numeric 2 bytes -32768 -
data +32767
Down Loads
Down loads without fractions (Whole
ACT Malappuram numbers)
ACT Malappuram
Long To represent large 4 bytes 214 crore
Source Book
numeric
Source Book (Aprx)
CE Activities data without fractions
CE Activities
(large Whole numbers)
Khalil's Profile
Khalil's Profile Single To represent numeric 4 bytes (7 digit
data Fractional
part)
with fractions
(Single precision floating
point numbers)
Double To represent large 8 bytes (16 digits
numeric Fractional
part)
data with fractions
(Double precision
floating
point numbers)
Currency To represent financial 8 bytes (4 digits
data Fractional
part)

1 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

Date To store date and time in 8 bytes


a format
Boolean For logic variables to 2 bytes
store
true or false
Variant It can contain any type 22 bytes
of data
+ string length
Variables
They are named storage locations to hold data. At run time we
can change the content of a variable.
Declaring variables

Syntax
Dim Variablename As Datatype

Eg: -
Dim amount As currency
Dim mark As integer
Dim name As string
Variable naming rules
It must be unique not a key word.
It can contain maximum 255 characters.
It must begin with an alphabet.
Symbols, Special symbols, space are not allowed except underscore.
Constants
They are values stored in a variable. They are numeric constants
and string constant.
Numeric constants may be integer, long, single, double.
Eg:- Dim age As Integer
Age=20
String constants enclosed in double quotes.
Eg: - Dim state As String
state= Kerala
Operators
They are symbols used in an expression or operation. Data stored in
a variable or constants are processed by using operators.
They are Arithmetic Operators, Relational Operators, Logical
Operators, and Concatenation Operator.

2 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

Arithmetic Operators
Operator Usage Example A=5, B=2
+ Addition A+B (7)
- Subtraction A-B (3)
* (Asterisk) Multiplication A*B (10)
/ Division A/B (2.5)
\ Integer Division A\B (2)
Mod Reminder of division A mod B (1)
^ (Cap) Exponentiation A ^ B (25)

Relational Operators
They are used to check some conditions. Its result is either true or
false. They are
Operator Usage Example (A=6, B=9)
= Equal to A=B (False)
< Less than A<B (True)
> Greater than A>B (False)
<= Less than or equal to A<=B (True)
>= Greater than or equal to A>=B (False)
<> Not equal to A<>B (True)

Logical Operators
It helps us to combine two relational operations. Its output is also
true or false. They are AND, OR, NOT
If A and B are outputs of any relational operations, then
A B A AND B A OR B NOT A NOT B
T T T T F F
T F F T F T
F T F T T F
F F F F T T

Concatenation Operator
It is used to join two strings.
Eg:-
Dim a, b, c as string
a= Together
b= to win

3 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

c= a&b
Its output is: Together to win.
Control Structures
They are used to alter the normal/ sequential execution of a
program. They are classified into two, Decision statements and Loop
statements.
Decision statements
It contains an expression (Relational or Logical) it evaluates the
condition first and executes a group of statements according to that
condition. They are
If..then.
If.Then.else.
If..then.Else if.else.

Select case
Ifthen

Syntax:
If <condition> then
<Statements>
End if

Eg:-
If a>b then
Msgbox a is large
Here the condition evaluates first, if it is true the statements will be
executed otherwise exit from if statement.
If.Then.else.

Syntax:
If <condition> then
<Statement1>
Else
<statement2>
End if

Eg:-
If a>b then
Msgbox a is large
Else
Msgbox b is large

4 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

End if
Here the condition evaluates first, if it is true the statement1 will be
executed otherwise statement2 will be executed.
If..then.Else if.else.
Syntax
If <condition1> then
<statement1>
elseif <condition2>
<statement2>
elseif <condition3>
<statement3>
.
.

else
<statements>
end if
Eg:-
If percent > 90 Then
Text3.Text = "A+"
ElseIf percent > 80 AND percent < 90 Then
Text3.Text = "A"
ElseIf percent > 70 AND percent < 80 Then
Text3.Text = "B+"
ElseIf percent > 60 AND percent < 70 Then
Text3.Text = "B"
ElseIf percent > 50 AND percent < 60 Then
Text3.Text = "C+"
ElseIf percent > 40 AND percent < 50 Then
Text3.Text = "C"
ElseIf percent > 30 AND percent < 40 Then
Text3.Text = "D+"
Else
Text3.Text = "D"
End if

5 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

It will display the grade according to the percentage. Here we


can include any number of conditions and it works with its true or false
results.
Select case statement
The select case statement is used to check different values for an
expression.
Syntax
Select case <Expression>
Case <value1>
<statement1>
Case <value2>
<statement2>
Case <value3>
<statement3>

..
case else
<statements>
End select

Eg:-
Private Sub Command1_Click()
numday = Text1.Text
Select Case numday
Case 1
MsgBox "Sunday"
Case 2
MsgBox "Monday"
Case 3
MsgBox "Tuesday"
Case 4
MsgBox "Wednesday"
Case 5
MsgBox "Thursday"
Case 6
MsgBox "Friday"

6 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

Case 7
MsgBox "Saturday"
Case Else
MsgBox "Enter a valid number of day"
End Select
End Sub

It display the day in a week if the input is 1 to 7 otherwise displays a


message box with message "Enter a valid number of day".
Loop statements
Loop statements are used to execute a group of statements
repeatedly.
In a loop there is three elements first one is an initialization of loop
control variable (To control the repeated execution of statements),
second one is the condition checking of loop control variable, third one
is updating of loop control variable and last one is loop body (Group of
statements that are to be executed repeatedly).
Loop statements are classified as follows,
Doloop (Do while.loop, Do untilloop)
While.wend

For..next
Do.loop
Syntax
<Initialization expression>
Do while <Condition expression >
<Body of loop>
<Updating expression >
Loop
Eg:-
Private Sub Command1_Click()
i=1
Do While i <= 10
Print i
i=i+1
Loop
End Sub
It will print 1 to 10 on the form. Here Body of loop will executed
repeatedly if the condition is true until it false.
Do until..loop

7 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

Syntax
<Initialization expression>
Do until <Condition expression >
<Body of loop>
<Updating expression >
Loop
Eg:-
Private Sub Command1_Click()
i=1
Do Until i > 10
Print i
i=i+1
Loop
End Sub
It will print 1 to 10 on the form. Here Body of loop will executed
repeatedly if the condition is false until it true.
While.wend
Syntax
<Initialization expression>
While <Condition expression >
<Body of loop>
<Updating expression >
Wend

Eg:-
Private Sub Command1_Click()
i=1
While i <= 10
Print i
i=i+1
Wend
End Sub
It will print 1 to 10 on the form. Here Body of loop will executed
repeatedly if the condition is true until it false, i.e. same as do while loop.
For..Next
Syntax

8 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

For <Loopcontrolvariable> = Ist to Last <Step Incrementt/Decrement>


<Body of loop>
Next <Loopcontrolvariable>

Eg:-
Private Sub Command1_Click()
For i = 1 To 10 Step 1
Print i
Next i
End Sub
It will print 1 to 10 on the form. Here Body of loop will executed
repeatedly if the value of loop control variable equal to 10.
Nesting of control structures
If one control structure contains another control structure inside in
its body is called nesting of control structures.
It may be
A decision within another decision
A decision within another loop
A loop within another loop
A loop within another decision

Eg:-
Private Sub Command1_Click()
For i = 1 To 10
If i <= 5 Then
Print i
End If
Next i
End Sub

It will print 1 to 5 on the form.


Exit statement
It is used to exit from a loop conditionally.
Eg:-
Private Sub Command1_Click()
For i = 1 To 10
Print i
If i = 5 Then Exit For

9 of 10 7/25/17, 7:46 PM
Chapter 12: Elements of Visual Basic Programming - act malappuram https://sites.google.com/site/togethertowinbykhalil/home/syllabus/theory-...

Next i
End Sub
It will print 1 to 5 on the form then exit from the for loop statement.
Goto statement
It is used to jump from one line of statement to another statement
unconditionally.
Eg:-
Private Sub Command1_Click()
a = Text1.Text
b = Text2.Text
If b = 0 Then
GoTo Error
Error:
MsgBox "Division is not possible"
Else
c=a/b
MsgBox c
End If
End Sub
It will produce the divided result if b not equal to zero otherwise displays
a message box with message "Division is not possible".
End statement
It indicates the termination of a VB program. It closes the running
windows of VB Program.
Private Sub Command1_Click()
End
End Sub

Report Abuse | Powered By Google Sites

10 of 10 7/25/17, 7:46 PM

You might also like