0% found this document useful (0 votes)
19 views17 pages

Variables

Uploaded by

Sagar Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views17 pages

Variables

Uploaded by

Sagar Jha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

VARIABLES

ARE THE MEMORY LOCATIONS WHICH ARE USED


TO STORE VALUES TEMPORARILY
TYPES OF VARIABLES:-

1. NUMERIC- STORES NUMBERS(INTEGERS – POSITIVE & NEGATIVE NUMBERS )

SINGLE- SIMPLE FLOATING VALUE (DECIMAL- 7 DIGITS)

DOUBLE- FLOATING VALUE (DECIMAL- 15 DIGITS)

2.STRING – STORES ALPHA NUMERIC VALUES

REPRESNTED WITH -“ ”

3.BOOLEAN – STORES BOOLEAN VALUES


STORES ZERO /ONE AND TRUE OR FALSE
4.DATE – STORES IN DATE FORMAT –DD/MM/YY

5.OBJECT – STORES OBJECT (IMAGE OR DATA FILE)

6. VARIENT – STORES ANY TYPE OF DATA


EVERY VARIABLE HAS NAME OR VALUE .
RULES TO BE FOLLOWED WHILE WRITING VARIABLE NAME----

1. MUST BEGIN WITH AN ALPHABET

2. SHOULD NOT EXCEED 255 CHARACTERS.

3. TWO DIFFRENT VARIABLES SHOULD NOT HAVE SAME NAME.

4. NAME CAN HAVE COMBINATION OF ALPHABET, NUMBER &


SINGLE SPECIAL CHARACTER UNDERSCORE(_)
“ DECLARATION OF VARIABLES

1. EXPLICIT

USE DIM STATEMENT FOLLOWED


2. IMPLICIT

WITHOUT DECLARATION

BY THE NAME & DATA TYPE. ADDING NAME (SUFFIX TO VARIABLE)

DIM L AS INTEGER TABLE –SUFFIX FOR DIFF DATA TYPE.


DIM A AS DOUBLE
DATA TYPE SUFFIX

STRING $
INTEGER %
LONG &
SINGLE !
DOUBLE #
CURRENCY @
VISUAL BASIC ARITHMETIC OPERATIONS

OPERATOR OPERATIONS
+ ADDITION

- SUBTRACTION

* MULTIPLICATION

/ DIVISION

% MODULUS

^ EXPONENTIAL
VISUAL BASIC RELATIONAL OPERATIONS
OPERATOR OPERATIONS
> GREATER THAN

< LESS THAN

>= GREATER THAN OR


EQUAL TO
<= LESS THAN OR EQUAL
TO
== EQUAL TO

<> NOT EQUAL TO


ARRAYS
• AN ARRAY CAN BE DEFINED AS INFINITE COLLECTION OF
HOMOGENEOUS ELEMENTS.
• ALWAYS STORED IN CONSECUTIVE MEMORY LOCATION.
• A LIST OF ITEMS WHICH HOLDS SETS OF RELATED DATA IN
CONSECUTIVE MEMORY LOCATION
• CAN STORE MULTIPLE VALUES WHICH CAN BE REFERED BY
SINGLE NAME.
• MUST BE DECLARED USING DIM STATEMENT FOLLOWED BY
NAME OF THE ARRAY & MAXIMUM NUMBER OF ELEMENTS IT
HOLDS IN BRACKET
• EXAMPLE- DIM DAYS [7]
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY

7 DAYS STRING

0 1 2 6

ARRAY NAME- DAYS [7] DAYS [2]-TUESDAY


CONTROLLED FLOW STATEMENT
(CONDITIONAL STATEMENT)

• In Visual Basic language there are several keywords that are


used to alter the flow of the program.
• When the program is run, the statements are executed from
the top of the source file to the bottom. One by one. This
flow can be altered by specific keywords. Statements can be
executed multiple times.
• Conditional statements are executed only if a specific
condition is met.
1.IF………THEN STATEMENT
• The if…….. Then structure sets the condition & only if it is true. It
executes the statement followed by word then.
• Syntax:-
If(condition) then
Statement
End if
EXAMPLE
The If keyword is used to check if an expression is true.
If it is true, a statement is then executed.
The statement can be a single statement or a compound statement.
A compound statement consists of multiple statements enclosed
by the If/End If block.

If (n>0) then
Print “n is positive”
End if
1.IF………THEN…….ELSE
STATEMENT
• In this statement if the condition is true then the statement before the word else will
be executed .
• If the condition is false ,the statement after the wor else will be executed until it
finds the word end if
• Syntax:-
If(condition) then
Statement 1
Else statement 2
Endif
EXAMPLE
We can use the Else keyword to create a simple branch.
If the expression inside the brackets following
the If keyword evaluates to false,
the statement
following the Else keyword is automatically executed.

If (n>0) then
Print “n is positive”
Else
Print “n is negative”
Endif
Select statement
The Select statement is a selection control flow statement.
It allows the value of a variable or expression to control the flow of program
execution via a multi way branch.
It creates multiple branches in a simpler way
than using the combination of If, Else If statements.
We have a variable or an expression.
The Select keyword is used to test a value from
the variable or the expression against a list of values.
The list of values is presented with the Case keyword.
If the values match, the statement following the Case is executed.
There is an optional Case Else statement.
It is executed if no other match is found.
Dim grade As String

Select Case grade

Case "A"
print "High Distinction"
Case "B"
print "first class“
Case "C"
print "second class“
Case “D"
print "pass“
Case Else
print "Fail"

End Select

You might also like