SlideShare una empresa de Scribd logo
1 de 17
VB.NET:- Variable and Constants
BCA -501
2
Content
 Variable
 Variable Declarations
 Variable Declaration Example
 Variable Initialisations
 Getting Values from user
 Lvalues & Rvalues
 Constants
 Enumeration
 Scope of Variable
3
Variable
 A variable is used to hold the value that can be used further in the programming.
 A variable is a simple name used to store the value of a specific data type in computer memory.
 In VB.NET, each variable has a particular data type that determines the size, range, and fixed
space in computer memory.
 With the help of variable, we can perform several operations and manipulate data values in any
programming language.
4
Variable Declarations
The Dim statement is used for variable declaration and storage allocation for one or more
variables. The Dim statement is used at module, class, structure, procedure or block level. .
Each variable in the variable list has the following syntax and parts −
variablename[ ( [ boundslist ] ) ] [ As [ New ] datatype ] [ = initializer ]
Where,
 variablename − is the name of the variable
 boundslist − optional. It provides list of bounds of each dimension of an array variable.
 New − optional. It creates a new instance of the class when the Dim statement runs.
 datatype − Required if Option Strict is On. It specifies the data type of the variable.
 initializer − Optional if New is not specified. Expression that is evaluated and assigned to the
variable when it is created.
5
Variable Declarations Syntax
Syntax: Dim [Variable_Name] As [Defined Data Type]
Name Descriptions
Dim It is used to declare and allocate the space for one or more variables in memory.
Variable_Name It defines the name of the variable to store the values.
As It is a keyword that allows you to define the data type in the declaration statement.
Data Type It defines a data type that allows variables to store data types such as Char, String, Integer,
Decimal, Long, etc.
Value Assign a value to the variable.
6
Variable Declarations Example
Dim Roll_no As Integer
Dim Emp_name As String
Dim Salary As Double
Dim Emp_id, Stud_id As Integer
Dim result_status As Boolean
Note:
If we want to declare more than one variable in the same line, we must separate each variable with a comma.
Dim Variable_name1 As DataType1, variable_name2 As DataType2, Variable_name3 As DataType3
7
Variable Initialization
 After the declaration of a variable, we must assign a value to the variable. The following syntax
describes the initialization of a variable:
Syntax: Variable_name = value
Dim Roll_no As Integer 'declaration of Roll_no
Roll_no = 101 'initialization of Roll_no
Initialize the Emp_name
Dim Emp_name As String
Emp_name = “Jaya" 'Here Emp_name variable assigned a value of Jaya
Initialize a Boolean variable
Dim status As Boolean 'Boolean value can be True or False.
status = True 'Initialize status value to True
Initialzation at the time of declaration:
Dim Roll_no As Integer = 101
Dim Emp_name As String = " Stephen Robert "
8
Getting Values from the User:
 In VB.NET, the Console class provides the Readline() function in the System namespace.
 It is used to take input from the user and assign a value to a variable
Dim name As String
name = Console.ReadLine()
Or name = Console.ReadLine
Imports System
Module User_Data
Sub Main()
Dim num As Integer
Dim age As Double
Dim name As String
Console.WriteLine("Enter your favourite number")
' Console.ReadLine or Console.ReadLine() takes value from the user
num = Console.ReadLine
Console.WriteLine(" Enter Your Good name")
'Read string data from the user
name = Console.ReadLine
Console.WriteLine(" Enter your Age")
age = Console.ReadLine
Console.WriteLine(" You have entered {0}", num)
Console.WriteLine(" You have entered {0}", name)
Console.WriteLine(" You have entered {0}", age)
Console.ReadKey()
End Sub
End Module
Note: Console.Read() and
Console.ReadKey() function is
used to read a single character
from the user.
9
Lvalues & Rvalues
 Lvalue: It is an lvalue expression that refers to a memory location for storing the address of a
variable. An lvalue is a variable that can appear to the left or right of the assignment operator to
hold values. Furthermore, in comparison to or swapping the variables' values, we can also
define the variable on both sides (left or right-side) of the assignment operator.
Dim num As Integer
Num = 5
Or
Dim num As Integer = 5
But when we write the following statement, it generates a compile-time error because it is not a
valid statement.
Dim x As Integer
10 = x
 Rvalue: It is an rvalue expression that is used to store a value in some address of memory. An
rvalue can appear only on the right- hand side because it is a value of the variable that defines
on the right-hand side.
Dim college_name As String
college_name = “ISM" // rvalue define at right side of the assignment operator.
10
Constants in VB.NET
 The name constant refers to a fixed value that cannot be changed during the execution of a program.
 It is also known as literals.
 These constants can be of any data type, such as Integer, Double, String, Decimal, Single, character, enum,
etc.
 In VB.NET, const is a keyword that is used to declare a variable as constant. The Const statement can be
used with module, structure, procedure, form, and class.
Const constname As datatype = value
Item Name Descriptions
Const It is a Const keyword to declare a variable as constant.
Constname It defines the name of the constant variable to store the values.
As It is a keyword that allows you to define the data type in the declaration statement.
Data Type It defines a data type that allows variables to store data types such as Char, String,
Integer, Decimal, Long, etc.
Value Assign a value to the variable as constant.
11
Print and Display Constant
Const Name Descriptions
vbCrLf Carriage return/linefeed character combination
vbCr Carriage return character
vbLf Linefeed character
vbNewLine Newline character
vbNullChar Null character
vbNullString Not the same as a zero-length string (""); used for calling external procedures.
vbObjectError Error number. User-defined error numbers should be greater than this value. For example:
Err.Raise(Number) = vbObjectError + 1000
vbTab Tab character.
vbBack Backspace character.
12
Enumerations in VB.NET
 An enumerated type is declared using the Enum statement.
 The Enum statement declares an enumeration and defines the values of its members.
 The Enum statement can be used at the module, class, structure, procedure, or block level.
Each member in the memberlist has the following syntax and
parts:
[< attribute list >] member name [ = initializer ]
Where,
name − specifies the name of the member. Required.
initializer − value assigned to the enumeration member. Optional.
Example:
Enum Colors
red = 1
orange = 2
yellow = 3
green = 4
azure = 5
blue = 6
violet = 7
End Enum
13
Print and Display Constant
Const Name Descriptions
vbCrLf Carriage return/linefeed character combination
vbCr Carriage return character
vbLf Linefeed character
vbNewLine Newline character
vbNullChar Null character
vbNullString Not the same as a zero-length string (""); used for calling external procedures.
vbObjectError Error number. User-defined error numbers should be greater than this value. For example:
Err.Raise(Number) = vbObjectError + 1000
vbTab Tab character.
vbBack Backspace character.
14
Scope of Variables
The scope of a variable determines the accessible range of a defined variable at the time of
declaration in any block, module, and class.
It can be accessed, if the variable is in a particular region or scope in the same block. And if the
variable goes beyond the region, its scope expires.
The following are the methods to represent the scope of a variable in VB.NET.
1. Procedure Scope
2. Module Scope
3. Public Scope
15
Procedure Scope
 A local variable is a type of variable defined within a procedure scope, block, or function. It is
available with a code inside the procedure, and it can be declared using the Dim or
static statement.
 These variables are not accessible from outside of the local method. However, the local
variable can be easily accessed by the nested programming function in the same method.
Dim X As Integer
 Local variables exist until the procedure in which they are declared is executed. Once a
procedure is executed, the values of its local variables will be lost, and the resources used by
these variables will be released. And when the block is executed again, all the local variables
are rearranged.
16
Module Scope
 All existing procedures can easily identify a variable that is declared inside a module sheet is
called a module-level variable.
 The defined module variable is visible to all procedures within that module only, but it is not
available for other module's procedures.
 The Dim or private statement at the top of the first procedure declaration can be declared the
module-level variables. It means that these variables cannot be declared inside any procedure
block.
 Further, these variables are useful to share information between the procedures in the same
module.
 And one more thing about the module-level variable is that these variables can remains
existence as long as the module is executed.
17
Global Scope
 As the name defines, a global variable is a variable that is used to access the
variables globally in a program.
 It means these variables can be accessed by all the procedures or modules available in a
program.
 To access the variables globally in a program, we need to use the friend or public
keyword with a variable in a module or class at the top of the first procedure function.
 Global scope is also known as the Namespace scope.
'Global declaration of a variable
Public str As String = "Hello, Programmer."
Public topic As String
Public exp As Integer

Más contenido relacionado

La actualidad más candente

Java Data Types
Java Data TypesJava Data Types
Java Data TypesSpotle.ai
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVAAnkita Totala
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#Dr.Neeraj Kumar Pandey
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ LanguageWay2itech
 
Data types in python
Data types in pythonData types in python
Data types in pythonRaginiJain21
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of ConstructorsDhrumil Panchal
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variablesPushpendra Tyagi
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in JavaSpotle.ai
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2MOHIT TOMAR
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming Kamal Acharya
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++ Hridoy Bepari
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and FunctionsJussi Pohjolainen
 

La actualidad más candente (20)

Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Array in c#
Array in c#Array in c#
Array in c#
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Typedef
TypedefTypedef
Typedef
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Java basics and java variables
Java basics and java variablesJava basics and java variables
Java basics and java variables
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2Datatype in c++ unit 3 -topic 2
Datatype in c++ unit 3 -topic 2
 
Storage Class in C Progrmming
Storage Class in C Progrmming Storage Class in C Progrmming
Storage Class in C Progrmming
 
Basic Data Types in C++
Basic Data Types in C++ Basic Data Types in C++
Basic Data Types in C++
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
 

Similar a Variable and constants in Vb.NET

C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE jatin batra
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio) rnkhan
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)rnkhan
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Nettjunicornfx
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYRajeshkumar Reddy
 
Variables and calculations_chpt_4
Variables and calculations_chpt_4Variables and calculations_chpt_4
Variables and calculations_chpt_4cmontanez
 
C programming session 04
C programming session 04C programming session 04
C programming session 04Dushmanta Nath
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01Zafor Iqbal
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxSaqlainYaqub1
 

Similar a Variable and constants in Vb.NET (20)

C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
C# language basics (Visual Studio)
C# language basics (Visual Studio) C# language basics (Visual Studio)
C# language basics (Visual Studio)
 
C# language basics (Visual studio)
C# language basics (Visual studio)C# language basics (Visual studio)
C# language basics (Visual studio)
 
Procedures functions structures in VB.Net
Procedures  functions  structures in VB.NetProcedures  functions  structures in VB.Net
Procedures functions structures in VB.Net
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
 
Shanks
ShanksShanks
Shanks
 
C UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDYC UNIT-3 PREPARED BY M V B REDDY
C UNIT-3 PREPARED BY M V B REDDY
 
Variables and calculations_chpt_4
Variables and calculations_chpt_4Variables and calculations_chpt_4
Variables and calculations_chpt_4
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01C Sharp: Basic to Intermediate Part 01
C Sharp: Basic to Intermediate Part 01
 
C language 3
C language 3C language 3
C language 3
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
 
Java part 2
Java part  2Java part  2
Java part 2
 
C++ version 1
C++  version 1C++  version 1
C++ version 1
 

Más de Jaya Kumari

Python data type
Python data typePython data type
Python data typeJaya Kumari
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonJaya Kumari
 
Variables in python
Variables in pythonVariables in python
Variables in pythonJaya Kumari
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by pythonJaya Kumari
 
Decision statements
Decision statementsDecision statements
Decision statementsJaya Kumari
 
Loop control statements
Loop control statementsLoop control statements
Loop control statementsJaya Kumari
 
Looping statements
Looping statementsLooping statements
Looping statementsJaya Kumari
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.netJaya Kumari
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netJaya Kumari
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.netJaya Kumari
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespaceJaya Kumari
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net Jaya Kumari
 
Java script Basic
Java script BasicJava script Basic
Java script BasicJaya Kumari
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script AdvanceJaya Kumari
 

Más de Jaya Kumari (20)

Python data type
Python data typePython data type
Python data type
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Variables in python
Variables in pythonVariables in python
Variables in python
 
Basic syntax supported by python
Basic syntax supported by pythonBasic syntax supported by python
Basic syntax supported by python
 
Oops
OopsOops
Oops
 
Inheritance
InheritanceInheritance
Inheritance
 
Overloading
OverloadingOverloading
Overloading
 
Decision statements
Decision statementsDecision statements
Decision statements
 
Loop control statements
Loop control statementsLoop control statements
Loop control statements
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Operators used in vb.net
Operators used in vb.netOperators used in vb.net
Operators used in vb.net
 
Keywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.netKeywords, identifiers and data type of vb.net
Keywords, identifiers and data type of vb.net
 
Introduction to vb.net
Introduction to vb.netIntroduction to vb.net
Introduction to vb.net
 
Frame class library and namespace
Frame class library and namespaceFrame class library and namespace
Frame class library and namespace
 
Introduction to .net
Introduction to .net Introduction to .net
Introduction to .net
 
Jsp basic
Jsp basicJsp basic
Jsp basic
 
Java script Basic
Java script BasicJava script Basic
Java script Basic
 
Sgml and xml
Sgml and xmlSgml and xml
Sgml and xml
 
Java script Advance
Java script   AdvanceJava script   Advance
Java script Advance
 
Html form
Html formHtml form
Html form
 

Último

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 

Último (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

Variable and constants in Vb.NET

  • 1. VB.NET:- Variable and Constants BCA -501
  • 2. 2 Content  Variable  Variable Declarations  Variable Declaration Example  Variable Initialisations  Getting Values from user  Lvalues & Rvalues  Constants  Enumeration  Scope of Variable
  • 3. 3 Variable  A variable is used to hold the value that can be used further in the programming.  A variable is a simple name used to store the value of a specific data type in computer memory.  In VB.NET, each variable has a particular data type that determines the size, range, and fixed space in computer memory.  With the help of variable, we can perform several operations and manipulate data values in any programming language.
  • 4. 4 Variable Declarations The Dim statement is used for variable declaration and storage allocation for one or more variables. The Dim statement is used at module, class, structure, procedure or block level. . Each variable in the variable list has the following syntax and parts − variablename[ ( [ boundslist ] ) ] [ As [ New ] datatype ] [ = initializer ] Where,  variablename − is the name of the variable  boundslist − optional. It provides list of bounds of each dimension of an array variable.  New − optional. It creates a new instance of the class when the Dim statement runs.  datatype − Required if Option Strict is On. It specifies the data type of the variable.  initializer − Optional if New is not specified. Expression that is evaluated and assigned to the variable when it is created.
  • 5. 5 Variable Declarations Syntax Syntax: Dim [Variable_Name] As [Defined Data Type] Name Descriptions Dim It is used to declare and allocate the space for one or more variables in memory. Variable_Name It defines the name of the variable to store the values. As It is a keyword that allows you to define the data type in the declaration statement. Data Type It defines a data type that allows variables to store data types such as Char, String, Integer, Decimal, Long, etc. Value Assign a value to the variable.
  • 6. 6 Variable Declarations Example Dim Roll_no As Integer Dim Emp_name As String Dim Salary As Double Dim Emp_id, Stud_id As Integer Dim result_status As Boolean Note: If we want to declare more than one variable in the same line, we must separate each variable with a comma. Dim Variable_name1 As DataType1, variable_name2 As DataType2, Variable_name3 As DataType3
  • 7. 7 Variable Initialization  After the declaration of a variable, we must assign a value to the variable. The following syntax describes the initialization of a variable: Syntax: Variable_name = value Dim Roll_no As Integer 'declaration of Roll_no Roll_no = 101 'initialization of Roll_no Initialize the Emp_name Dim Emp_name As String Emp_name = “Jaya" 'Here Emp_name variable assigned a value of Jaya Initialize a Boolean variable Dim status As Boolean 'Boolean value can be True or False. status = True 'Initialize status value to True Initialzation at the time of declaration: Dim Roll_no As Integer = 101 Dim Emp_name As String = " Stephen Robert "
  • 8. 8 Getting Values from the User:  In VB.NET, the Console class provides the Readline() function in the System namespace.  It is used to take input from the user and assign a value to a variable Dim name As String name = Console.ReadLine() Or name = Console.ReadLine Imports System Module User_Data Sub Main() Dim num As Integer Dim age As Double Dim name As String Console.WriteLine("Enter your favourite number") ' Console.ReadLine or Console.ReadLine() takes value from the user num = Console.ReadLine Console.WriteLine(" Enter Your Good name") 'Read string data from the user name = Console.ReadLine Console.WriteLine(" Enter your Age") age = Console.ReadLine Console.WriteLine(" You have entered {0}", num) Console.WriteLine(" You have entered {0}", name) Console.WriteLine(" You have entered {0}", age) Console.ReadKey() End Sub End Module Note: Console.Read() and Console.ReadKey() function is used to read a single character from the user.
  • 9. 9 Lvalues & Rvalues  Lvalue: It is an lvalue expression that refers to a memory location for storing the address of a variable. An lvalue is a variable that can appear to the left or right of the assignment operator to hold values. Furthermore, in comparison to or swapping the variables' values, we can also define the variable on both sides (left or right-side) of the assignment operator. Dim num As Integer Num = 5 Or Dim num As Integer = 5 But when we write the following statement, it generates a compile-time error because it is not a valid statement. Dim x As Integer 10 = x  Rvalue: It is an rvalue expression that is used to store a value in some address of memory. An rvalue can appear only on the right- hand side because it is a value of the variable that defines on the right-hand side. Dim college_name As String college_name = “ISM" // rvalue define at right side of the assignment operator.
  • 10. 10 Constants in VB.NET  The name constant refers to a fixed value that cannot be changed during the execution of a program.  It is also known as literals.  These constants can be of any data type, such as Integer, Double, String, Decimal, Single, character, enum, etc.  In VB.NET, const is a keyword that is used to declare a variable as constant. The Const statement can be used with module, structure, procedure, form, and class. Const constname As datatype = value Item Name Descriptions Const It is a Const keyword to declare a variable as constant. Constname It defines the name of the constant variable to store the values. As It is a keyword that allows you to define the data type in the declaration statement. Data Type It defines a data type that allows variables to store data types such as Char, String, Integer, Decimal, Long, etc. Value Assign a value to the variable as constant.
  • 11. 11 Print and Display Constant Const Name Descriptions vbCrLf Carriage return/linefeed character combination vbCr Carriage return character vbLf Linefeed character vbNewLine Newline character vbNullChar Null character vbNullString Not the same as a zero-length string (""); used for calling external procedures. vbObjectError Error number. User-defined error numbers should be greater than this value. For example: Err.Raise(Number) = vbObjectError + 1000 vbTab Tab character. vbBack Backspace character.
  • 12. 12 Enumerations in VB.NET  An enumerated type is declared using the Enum statement.  The Enum statement declares an enumeration and defines the values of its members.  The Enum statement can be used at the module, class, structure, procedure, or block level. Each member in the memberlist has the following syntax and parts: [< attribute list >] member name [ = initializer ] Where, name − specifies the name of the member. Required. initializer − value assigned to the enumeration member. Optional. Example: Enum Colors red = 1 orange = 2 yellow = 3 green = 4 azure = 5 blue = 6 violet = 7 End Enum
  • 13. 13 Print and Display Constant Const Name Descriptions vbCrLf Carriage return/linefeed character combination vbCr Carriage return character vbLf Linefeed character vbNewLine Newline character vbNullChar Null character vbNullString Not the same as a zero-length string (""); used for calling external procedures. vbObjectError Error number. User-defined error numbers should be greater than this value. For example: Err.Raise(Number) = vbObjectError + 1000 vbTab Tab character. vbBack Backspace character.
  • 14. 14 Scope of Variables The scope of a variable determines the accessible range of a defined variable at the time of declaration in any block, module, and class. It can be accessed, if the variable is in a particular region or scope in the same block. And if the variable goes beyond the region, its scope expires. The following are the methods to represent the scope of a variable in VB.NET. 1. Procedure Scope 2. Module Scope 3. Public Scope
  • 15. 15 Procedure Scope  A local variable is a type of variable defined within a procedure scope, block, or function. It is available with a code inside the procedure, and it can be declared using the Dim or static statement.  These variables are not accessible from outside of the local method. However, the local variable can be easily accessed by the nested programming function in the same method. Dim X As Integer  Local variables exist until the procedure in which they are declared is executed. Once a procedure is executed, the values of its local variables will be lost, and the resources used by these variables will be released. And when the block is executed again, all the local variables are rearranged.
  • 16. 16 Module Scope  All existing procedures can easily identify a variable that is declared inside a module sheet is called a module-level variable.  The defined module variable is visible to all procedures within that module only, but it is not available for other module's procedures.  The Dim or private statement at the top of the first procedure declaration can be declared the module-level variables. It means that these variables cannot be declared inside any procedure block.  Further, these variables are useful to share information between the procedures in the same module.  And one more thing about the module-level variable is that these variables can remains existence as long as the module is executed.
  • 17. 17 Global Scope  As the name defines, a global variable is a variable that is used to access the variables globally in a program.  It means these variables can be accessed by all the procedures or modules available in a program.  To access the variables globally in a program, we need to use the friend or public keyword with a variable in a module or class at the top of the first procedure function.  Global scope is also known as the Namespace scope. 'Global declaration of a variable Public str As String = "Hello, Programmer." Public topic As String Public exp As Integer