You are on page 1of 4

Subject Grade Date Block week Unit/Lesson/Topic Worksheet

ICT 9 2 1 Constant 3 out of 16


Use lists, variables, constants, inputs, outputs and assignments.
Learning Outcome
/Objective:
• Differentiate between variables and constants
• Assign values to variable or constants
Student Name: ………………………………………………………………………………………………………………………. Class 9

Contents
1. Constants in Visual Basic
2. Constant Declaration
3. Visual Basic Constant Examples

Prepared by P a g e |1
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 Constant 3 out of 16
Objective: • Differentiate between variables and constants
Student Name: ………………………………………………………………………………………………………………………. Class 9

To start creating programs you have to differentiate between two important


concepts Variables and Constant

Prepared by P a g e |2
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 Constant 3 out of 16
Objective: • Assign values to variable or constants
Student Name: ………………………………………………………………………………………………………………………. Class 9

Constants in Visual Basic


• A constant is a memory location that holds data that cannot be changed during the
execution of a program.
• The constants are treated just like regular variables, except that their values cannot
be modified after their definition.
• Constants can be of any of the basic data types like an integer constant, a floating
constant, a character constant, or a string literal.

Constant Declaration

• You declare a constant with the Const statement, using the same guidelines you
would for creating a variable name.

Syntax Const Constname As datatype = value

• A declaration statement is made up of four parts which are as follows:


[1] Const: It is a Const keyword to declare a variable as constant.
[2] Constname: It defines the name of the constant variable to store the values.
[3] AS: is a keyword in Visual basic.
[4] Data Type: It defines a data type that allows variables to store data types such as Char,
String, Integer, Decimal, Long, etc.
[5] Value: specifies the value assigned to the constant.

EX:
Const name As String = "Suresh Dasari"
Const location As String = "Hyderabad"
Const age As Integer = 32

Prepared by P a g e |3
Subject Grade Date Block week Unit/Lesson/Topic Study sheet
ICT 9 2 1 Constant 3 out of 16
Objective: • Assign values to variable or constants
Student Name: ………………………………………………………………………………………………………………………. Class 9

Visual Basic Constant Examples


Following is the example of defining and using the constant fields in visual basic
programming language with Const keyword.

Module Module1
Sub Main)(
' Constant
Const name As String = "Ghadeer Mohamed"
Const location As String = "Qena"
Const age As Integer = 27
Console.WriteLine("Name: " & name)
Console.WriteLine("Location: " & location)
Console.WriteLine("Age: " & age)
Console.ReadLine()
End Sub
End Module
Module Module1
Sub Main)(
Const PI As Single = 3.14149
Dim radius, area As Single
Console.Write("Enter the radius value : ")
radius = Console.ReadLine
area = PI * radius * radius
Console.WriteLine()
Console.WriteLine("Area = " & area)
Console.ReadKey()
End Sub
End Module

Prepared by P a g e |4

You might also like