SlideShare a Scribd company logo
1 of 17
CHAPTER-03
Variable
Constants
Culculation
Prepared by: Mr Pork Naron
Objective
 The student will be able to:
 What is Variable, constant
 Know how to declare variable and Constant
 Rule of naming variable and Constant
 Using Data type
 Scope of Variable and Constant
 Converting data output
 Format output
 Develop small project using calculator
Prepared by: Mr Pork Naron
Variable
 Provide a means to store data values that are
not stored in files.
 Support the computation of values through
their use in formulas in assignment
 Represent locations in a computer's memory
 are assigned a unique name for reference when
writing computer code statements.
Prepared by: Mr Pork Naron
DataType
Prepared by: Mr Pork Naron
DataType Description Bytes
Text Data
String Alphanumeric data such as letters of the alphabet Size varies
Char
Stores single Unicode characters (supports any international
language).
2
Numeric Data
Decimal often used to store dollars/cents 16
Double Double-precision numeric values with 14 digits of accuracy 8
Single Single-precision numeric values with 6 digits of accuracy 4
Short numeric values in the range -32,768 to 32,767 2
Integer
numeric values in the range -2,147,483,648 to
+2,147,483,647
4
Long numeric values that are very, very large 8
DataType(Cont)
Prepared by: Mr Pork Naron
DataType Description Bytes
Special DataType
Boolean True or False 2
Byte
Stores binary data of values 0 to 255 – can be used to store
ASCIIcharacter code values
1
Date Stores dates in the form 1/1/0001 to 12/31/9999 8
Object Any type of data 4
Naming Rules for
Variable and Constant
Prepared by: Mr Pork Naron
 Can be letters, digits, and the underscore,
but must begin with a letter
 cannot contain spaces or periods
 cannot be VB reserved words such as LET,
PRINT, DIM, or CONST
 are not case sensitive. This means that
TotalInteger, TOTALINTEGER, and
totalinteger are all equivalent names
Naming Convention
Prepared by: Mr Pork Naron
 Create meaningful names
 Avoid using abbreviations
 Begin each name with an uppercase letter and
capitalize each successive word in the name.
 Use mixed case (such as AmountDueDecimal) for
variables – use Uppercase for constant names
(such as TAX_RATE_SINGLE)
Declaring Variable & Constant
Prepared by: Mr Pork Naron
Variable
 Dim
 Eg: Dim EmployeeName as String
Constant
 Const
 Eg: Const Age as Integer=23
Scope of Variables and Constants
Prepared by: Mr Pork Naron
 Namespace : Public Shared(visible in whole
project)
 Module level: Private(variable), Const (
constant) – visile any procedure in specific form.
 Local : Dim(variable), Const (constant) visible
in only one procedure
 Block : Dim(variable), Const(constant) – visible
in only a portion of procedure
Converting Input Data Types
Prepared by: Mr Pork Naron
 Text property – always stores string
values, even if the string looks like a
number.
 Parse method – converts a value from
a Text property to an equivalent
numeric value or other types
Converting Variable Values to Output
Data Types
Prepared by: Mr Pork Naron
 Use (.ToString) method to convert
variable value to output data
 TxtOutput.text = Output.ToString()
Arithmetic Operators
Prepared by: Mr Pork Naron
 + Addition
 - Subtraction
 * Multiplication
 / Division
 ^ Exponentiation
  Integer Division
 Mod Modulus Division
Order of Precedence
Prepared by: Mr Pork Naron
1. Values enclosed inside
parentheses (xxxx)
2. Exponentiation ^
3. Multiplication and Division(*,/)
4. Addition and Subtraction (+, -)
Order of Precedence(cont)
Prepared by: Mr Pork Naron
Eg: Assume that: X=2, Y=4, and Z=3
Order of Precedence(cont)
Prepared by: Mr Pork Naron
• mathematical notation and the equivalent VB
expression
Format Function
Prepared by: Mr Pork Naron
 FormatCurrency
 BalanceDueTextBox.Text = FormatCurrency(BalanceDueDecimal)
 FormatNumber
 AmountTextBox.Text = FormatNumber(AmountDouble)
 FormatPercent
 PercentFinishedTextBox.Text = FormatPercent(FinishedSingle)
 FormatDate
 DateTextBox.Text = FormatDateTime(StartDate, DateFormat.ShortDate)
 DateTextBox.Text = FormatDateTime(StartDate, DateFormat.LongDate)
 TimeTextBox.Text = FormatDateTime(StartDateTime,
DateFormat.ShortTime)
 TimeTextBox.Text = FormatDateTime(StartDateTime,
DateFormat.LongTime)
Compute Lab
Prepared by: Mr Pork Naron
Develop Small Calculator

More Related Content

What's hot

TextBox and RichTextBox in VB.Net
TextBox and RichTextBox in VB.NetTextBox and RichTextBox in VB.Net
TextBox and RichTextBox in VB.NetSaniya Saher
 
Effective Java - Always override toString() method
Effective Java - Always override toString() methodEffective Java - Always override toString() method
Effective Java - Always override toString() methodFerdous Mahmud Shaon
 
Error Detection N Correction
Error Detection N CorrectionError Detection N Correction
Error Detection N CorrectionAnkan Adhikari
 
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelSingle-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelUniversitas Pembangunan Panca Budi
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITASIT
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types Hemantha Kulathilake
 
Addressing modes Breifly
Addressing modes BreiflyAddressing modes Breifly
Addressing modes BreiflyTahir Jalali
 
Data Communication & Computer Networks : Data Types
Data Communication & Computer Networks : Data TypesData Communication & Computer Networks : Data Types
Data Communication & Computer Networks : Data TypesDr Rajiv Srivastava
 

What's hot (16)

TextBox and RichTextBox in VB.Net
TextBox and RichTextBox in VB.NetTextBox and RichTextBox in VB.Net
TextBox and RichTextBox in VB.Net
 
Effective Java - Always override toString() method
Effective Java - Always override toString() methodEffective Java - Always override toString() method
Effective Java - Always override toString() method
 
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
Ultra-efficient algorithms for testing well-parenthesised expressions by Tati...
 
Error Detection N Correction
Error Detection N CorrectionError Detection N Correction
Error Detection N Correction
 
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit ModelSingle-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
Single-Bit Parity Detection and Correction using Hamming Code 7-Bit Model
 
FUNDAMENTAL OF C
FUNDAMENTAL OF CFUNDAMENTAL OF C
FUNDAMENTAL OF C
 
..Ans 1
..Ans 1..Ans 1
..Ans 1
 
Learn C LANGUAGE at ASIT
Learn C LANGUAGE at ASITLearn C LANGUAGE at ASIT
Learn C LANGUAGE at ASIT
 
COM1407: Variables and Data Types
COM1407: Variables and Data Types COM1407: Variables and Data Types
COM1407: Variables and Data Types
 
Addressing modes Breifly
Addressing modes BreiflyAddressing modes Breifly
Addressing modes Breifly
 
Data types vbnet
Data types vbnetData types vbnet
Data types vbnet
 
Chapter 2.datatypes and operators
Chapter 2.datatypes and operatorsChapter 2.datatypes and operators
Chapter 2.datatypes and operators
 
Strings in c language
Strings in  c languageStrings in  c language
Strings in c language
 
Computer
ComputerComputer
Computer
 
LISP: Scope and extent in lisp
LISP: Scope and extent in lispLISP: Scope and extent in lisp
LISP: Scope and extent in lisp
 
Data Communication & Computer Networks : Data Types
Data Communication & Computer Networks : Data TypesData Communication & Computer Networks : Data Types
Data Communication & Computer Networks : Data Types
 

Viewers also liked

Building Your Online Following
Building Your Online FollowingBuilding Your Online Following
Building Your Online FollowingJason Crouch
 
Innovative Lesson Template
Innovative Lesson Template Innovative Lesson Template
Innovative Lesson Template Arun Murali
 
Turning employees into ambassadors in social media
Turning employees into ambassadors in social mediaTurning employees into ambassadors in social media
Turning employees into ambassadors in social mediaOkimo Clinic
 
Evasesión31 32
Evasesión31 32Evasesión31 32
Evasesión31 32keithlerma
 
Investigación sobre la realidad escolar
Investigación sobre la realidad escolarInvestigación sobre la realidad escolar
Investigación sobre la realidad escolarLoRy GoMez
 
Professional Development classes
Professional Development classesProfessional Development classes
Professional Development classesJoLynn Rodabaugh
 
Lo importante que es el realizar tus planeaciones
Lo importante que es el realizar tus planeacionesLo importante que es el realizar tus planeaciones
Lo importante que es el realizar tus planeacionesLoRy GoMez
 
Презентация
ПрезентацияПрезентация
Презентацияwolodka2
 
9 Things to Look for in an Agency Management System
9 Things to Look for in an Agency Management System9 Things to Look for in an Agency Management System
9 Things to Look for in an Agency Management SystemStrategic Insurance Software
 
Lap trinh-huong-doi-tuong-bang-c#
Lap trinh-huong-doi-tuong-bang-c#Lap trinh-huong-doi-tuong-bang-c#
Lap trinh-huong-doi-tuong-bang-c#Thanhlanh nguyen
 
Làm phim không khó
Làm phim không khóLàm phim không khó
Làm phim không khónhanai ho
 
Exposicion (1)
Exposicion (1)Exposicion (1)
Exposicion (1)chicapili
 

Viewers also liked (16)

Building Your Online Following
Building Your Online FollowingBuilding Your Online Following
Building Your Online Following
 
Innovative Lesson Template
Innovative Lesson Template Innovative Lesson Template
Innovative Lesson Template
 
Turning employees into ambassadors in social media
Turning employees into ambassadors in social mediaTurning employees into ambassadors in social media
Turning employees into ambassadors in social media
 
Socap 1
Socap 1Socap 1
Socap 1
 
P.p jorge
P.p  jorgeP.p  jorge
P.p jorge
 
Evasesión31 32
Evasesión31 32Evasesión31 32
Evasesión31 32
 
Investigación sobre la realidad escolar
Investigación sobre la realidad escolarInvestigación sobre la realidad escolar
Investigación sobre la realidad escolar
 
Professional Development classes
Professional Development classesProfessional Development classes
Professional Development classes
 
Lo importante que es el realizar tus planeaciones
Lo importante que es el realizar tus planeacionesLo importante que es el realizar tus planeaciones
Lo importante que es el realizar tus planeaciones
 
Pointer
PointerPointer
Pointer
 
Dia de muertos
Dia de muertosDia de muertos
Dia de muertos
 
Презентация
ПрезентацияПрезентация
Презентация
 
9 Things to Look for in an Agency Management System
9 Things to Look for in an Agency Management System9 Things to Look for in an Agency Management System
9 Things to Look for in an Agency Management System
 
Lap trinh-huong-doi-tuong-bang-c#
Lap trinh-huong-doi-tuong-bang-c#Lap trinh-huong-doi-tuong-bang-c#
Lap trinh-huong-doi-tuong-bang-c#
 
Làm phim không khó
Làm phim không khóLàm phim không khó
Làm phim không khó
 
Exposicion (1)
Exposicion (1)Exposicion (1)
Exposicion (1)
 

Similar to Chapter 03

Similar to Chapter 03 (20)

Variables and calculations_chpt_4
Variables and calculations_chpt_4Variables and calculations_chpt_4
Variables and calculations_chpt_4
 
Visual Basic Fundamentals
Visual Basic FundamentalsVisual Basic Fundamentals
Visual Basic Fundamentals
 
Chapter 03
Chapter 03Chapter 03
Chapter 03
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
UNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCAUNIT-II VISUAL BASIC.NET | BCA
UNIT-II VISUAL BASIC.NET | BCA
 
C++ programming
C++ programmingC++ programming
C++ programming
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
 
Ppt lesson 07
Ppt lesson 07Ppt lesson 07
Ppt lesson 07
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Data type
Data typeData type
Data type
 
Chapter 6 Intermediate Code Generation
Chapter 6   Intermediate Code GenerationChapter 6   Intermediate Code Generation
Chapter 6 Intermediate Code Generation
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
Intermediate code generation1
Intermediate code generation1Intermediate code generation1
Intermediate code generation1
 
C Sharp Nagina (1)
C Sharp Nagina (1)C Sharp Nagina (1)
C Sharp Nagina (1)
 
C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
 
Data types.pdf
Data types.pdfData types.pdf
Data types.pdf
 
Numeric Data Types & Strings
Numeric Data Types & StringsNumeric Data Types & Strings
Numeric Data Types & Strings
 
Unit - 1.ppt
Unit - 1.pptUnit - 1.ppt
Unit - 1.ppt
 
Python
PythonPython
Python
 

Recently uploaded

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 

Recently uploaded (20)

Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 

Chapter 03

  • 2. Objective  The student will be able to:  What is Variable, constant  Know how to declare variable and Constant  Rule of naming variable and Constant  Using Data type  Scope of Variable and Constant  Converting data output  Format output  Develop small project using calculator Prepared by: Mr Pork Naron
  • 3. Variable  Provide a means to store data values that are not stored in files.  Support the computation of values through their use in formulas in assignment  Represent locations in a computer's memory  are assigned a unique name for reference when writing computer code statements. Prepared by: Mr Pork Naron
  • 4. DataType Prepared by: Mr Pork Naron DataType Description Bytes Text Data String Alphanumeric data such as letters of the alphabet Size varies Char Stores single Unicode characters (supports any international language). 2 Numeric Data Decimal often used to store dollars/cents 16 Double Double-precision numeric values with 14 digits of accuracy 8 Single Single-precision numeric values with 6 digits of accuracy 4 Short numeric values in the range -32,768 to 32,767 2 Integer numeric values in the range -2,147,483,648 to +2,147,483,647 4 Long numeric values that are very, very large 8
  • 5. DataType(Cont) Prepared by: Mr Pork Naron DataType Description Bytes Special DataType Boolean True or False 2 Byte Stores binary data of values 0 to 255 – can be used to store ASCIIcharacter code values 1 Date Stores dates in the form 1/1/0001 to 12/31/9999 8 Object Any type of data 4
  • 6. Naming Rules for Variable and Constant Prepared by: Mr Pork Naron  Can be letters, digits, and the underscore, but must begin with a letter  cannot contain spaces or periods  cannot be VB reserved words such as LET, PRINT, DIM, or CONST  are not case sensitive. This means that TotalInteger, TOTALINTEGER, and totalinteger are all equivalent names
  • 7. Naming Convention Prepared by: Mr Pork Naron  Create meaningful names  Avoid using abbreviations  Begin each name with an uppercase letter and capitalize each successive word in the name.  Use mixed case (such as AmountDueDecimal) for variables – use Uppercase for constant names (such as TAX_RATE_SINGLE)
  • 8. Declaring Variable & Constant Prepared by: Mr Pork Naron Variable  Dim  Eg: Dim EmployeeName as String Constant  Const  Eg: Const Age as Integer=23
  • 9. Scope of Variables and Constants Prepared by: Mr Pork Naron  Namespace : Public Shared(visible in whole project)  Module level: Private(variable), Const ( constant) – visile any procedure in specific form.  Local : Dim(variable), Const (constant) visible in only one procedure  Block : Dim(variable), Const(constant) – visible in only a portion of procedure
  • 10. Converting Input Data Types Prepared by: Mr Pork Naron  Text property – always stores string values, even if the string looks like a number.  Parse method – converts a value from a Text property to an equivalent numeric value or other types
  • 11. Converting Variable Values to Output Data Types Prepared by: Mr Pork Naron  Use (.ToString) method to convert variable value to output data  TxtOutput.text = Output.ToString()
  • 12. Arithmetic Operators Prepared by: Mr Pork Naron  + Addition  - Subtraction  * Multiplication  / Division  ^ Exponentiation  Integer Division  Mod Modulus Division
  • 13. Order of Precedence Prepared by: Mr Pork Naron 1. Values enclosed inside parentheses (xxxx) 2. Exponentiation ^ 3. Multiplication and Division(*,/) 4. Addition and Subtraction (+, -)
  • 14. Order of Precedence(cont) Prepared by: Mr Pork Naron Eg: Assume that: X=2, Y=4, and Z=3
  • 15. Order of Precedence(cont) Prepared by: Mr Pork Naron • mathematical notation and the equivalent VB expression
  • 16. Format Function Prepared by: Mr Pork Naron  FormatCurrency  BalanceDueTextBox.Text = FormatCurrency(BalanceDueDecimal)  FormatNumber  AmountTextBox.Text = FormatNumber(AmountDouble)  FormatPercent  PercentFinishedTextBox.Text = FormatPercent(FinishedSingle)  FormatDate  DateTextBox.Text = FormatDateTime(StartDate, DateFormat.ShortDate)  DateTextBox.Text = FormatDateTime(StartDate, DateFormat.LongDate)  TimeTextBox.Text = FormatDateTime(StartDateTime, DateFormat.ShortTime)  TimeTextBox.Text = FormatDateTime(StartDateTime, DateFormat.LongTime)
  • 17. Compute Lab Prepared by: Mr Pork Naron Develop Small Calculator

Editor's Notes

  1. Create meaningful names – do not name a variable or constant X or Y or XInteger. Instead use names such as StudentNameString, CountStudentsInteger, and AmountDueDecimal. 2. Avoid using abbreviations unless the abbreviation is standard and well-accepted such as SSNString for storing social security number values. 3. Begin each name with an uppercase letter and capitalize each successive word in the name. 4. Use mixed case (such as AmountDueDecimal) for variables – use Uppercase for constant names (such as TAX_RATE_SINGLE).
  2. As part of the Input phase of the Input-Process-Output model, you must convert values from the Text property of a TextBox and store the converted values to memory variables. Text property – always stores string values, even if the string looks like a number. Parse method – converts a value from a Text property to an equivalent numeric value for storage to a numeric variable. Parse means to examine a string character by character and convert the value to another format such as decimal or integer.. In order to parse a string that contains special characters such as a decimal point, comma, or currency symbol, use the Globalization enumeration shown in the coding examples below. § If you don’t specify the Globalization value of Globalization.NumberStyles.Currency, then a value entered into a textbox controlsuch as $1,515.95 will NOT parse to Decimal. The Globalization value Globalization.NumberStyles.Number will allow the Integer.Parse method to parse a textbox value that contains a comma, such as 1,249. VB's Intellisense will display the various possible values for the Globalization enumeration. Example #1 – this example shows you how to declare numeric variables then store values to them from Textbox controls. -----------------Declare variables------------------ Dim PriceDecimal As Decimal Dim QuantityInteger As Integer ---------------Convert values from textbox controls to memory PriceDecimal = Decimal.Parse(PriceTextBox.Text,Globalization.NumberStyles.Currency) QuantityInteger = Integer.Parse(QuantityTextBox.Text,Globalization.NumberStyles.Number) Example #2 – this example shows you how to declare numeric variables and store values to them from Textbox controls using a single assignment statement in one step. ----------------------Declare variables and convert values from textbox controls to memory in a single statement Dim PriceDecimal As Decimal = Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency) Dim QuantityInteger As Integer = Integer.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Number) Older versions of VB used named functions to convert values. Examples are the CDec (convert to Decimal) and CInt (convert to Integer) functions shown here – you may encounter these functions in other VB books that you read or in the VB Help files. There are some advantages to these named functions: · A TextBox Text property value of $100.00 will NOT generate an error if you use the CDec function to convert the value as shown below—the data will convert satisfactorily. · The functions are faster and easier to type. 'Converts to decimal and Integer 3-Variables, Constants, and Calculations http://www.siue.edu/~dbock/cmis142/WebNotes/Ch3Notes/3-variables.htm 9 of 30 3/27/2014 3:26 PM PriceDecimal = CDec(PriceTextBox.Text) QuantityInteger = CInt(QuantityTextBox.Text)
  3. In order to display numeric variable values as output the values must be converted from numeric data types to string in order to store the data to the Text property of a TextBox control. Use the ToString method. These examples show converting strings to a numeric representation with 2 digits to the right of the decimal (N2) and currency with 2 digits to the right of the decimal (C2) as well as no digits to the right of a number (N0 – that is N zero, not N Oh).
  4. In order to display numeric variable values as output the values must be converted from numeric data types to string in order to store the data to the Text property of a TextBox control. Use the ToString method. These examples show converting strings to a numeric representation with 2 digits to the right of the decimal (N2) and currency with 2 digits to the right of the decimal (C2) as well as no digits to the right of a number (N0 – that is N zero, not N Oh).
  5. The order of precedence for expressions that have more than one operation is the same as for other programming languages. The order of precedence is applied to an expression by evaluating the expression from left to right for values within parentheses – within parentheses VB will process the expression from left to right looking for an applying the exponentiation operator, then again from left to right applying the multiplication and division operators, etc. This left to right application of operators continues in pass-after-pass working down the order of precedence. Use parentheses to control the application of the order of precedence of operations. · Example #1: (5 + 6) * 2 is evaluated: first as 5 + 6 = 11, because the parentheses force the addition operation to be evaluated before the multiplication operation, or next VB will multiple 11 by 2 to arrive at 22. · Example #2: 5 + 6 * 2 is evaluated: first as 6 * 2 = 12, because the multiplication operator is higher in the order of precedence, o next VB will add 5 to 12 to arrive at 17.
  6. The order of precedence for expressions that have more than one operation is the same as for other programming languages. The order of precedence is applied to an expression by evaluating the expression from left to right for values within parentheses – within parentheses VB will process the expression from left to right looking for an applying the exponentiation operator, then again from left to right applying the multiplication and division operators, etc. This left to right application of operators continues in pass-after-pass working down the order of precedence. Use parentheses to control the application of the order of precedence of operations. · Example #1: (5 + 6) * 2 is evaluated: first as 5 + 6 = 11, because the parentheses force the addition operation to be evaluated before the multiplication operation, or next VB will multiple 11 by 2 to arrive at 22. · Example #2: 5 + 6 * 2 is evaluated: first as 6 * 2 = 12, because the multiplication operator is higher in the order of precedence, o next VB will add 5 to 12 to arrive at 17.
  7. The order of precedence for expressions that have more than one operation is the same as for other programming languages. The order of precedence is applied to an expression by evaluating the expression from left to right for values within parentheses – within parentheses VB will process the expression from left to right looking for an applying the exponentiation operator, then again from left to right applying the multiplication and division operators, etc. This left to right application of operators continues in pass-after-pass working down the order of precedence. Use parentheses to control the application of the order of precedence of operations. · Example #1: (5 + 6) * 2 is evaluated: first as 5 + 6 = 11, because the parentheses force the addition operation to be evaluated before the multiplication operation, or next VB will multiple 11 by 2 to arrive at 22. · Example #2: 5 + 6 * 2 is evaluated: first as 6 * 2 = 12, because the multiplication operator is higher in the order of precedence, o next VB will add 5 to 12 to arrive at 17.