Data types, Variables and       Constants      Software Design &        Development                            1
Data TypesA program can’t do anything until you have reserved aspace in memory for the values used in itThis is called dec...
Data typesDepending on the type of data used by our program,we need to choose to use a particular data typeSome programs o...
Basic data typesDate   Covers most of the useful range!!   Anything from 1st Jan 100 to 31st Dec 9999   Time information i...
Basic data typesBoolean  For true or false values e.g. Yes / No answers  Can be used for numbers    0 = false    Any oth...
Basic data typesShort  whole numbers in the range –32,768 to 32,767  Examples: -32 or 10,000  needs 2 bytes of storage spa...
Basic data typesSingle  Numbers with decimal places and fractions  in the range -3.402823E38 to –1.401298E-45 for negative...
Variables - Naming conventionsHungarian notation is used in naming variablesThis is accepted as good programming practiceP...
VariablesPrefixessht = short         dte = dateint = integer       dec = decimalsng = single        bln = booleandbl = dou...
ConstantsUse a Constant where a value is needed but does notchange while program is running  e.g. VAT, Annual Leave, Pi, G...
Name the variableWrite down some suitable identifiers for thesevariables:  VAT  Your telephone number  Today’s date  Wheth...
Upcoming SlideShare
Loading in …5
×

Data types vbnet

336 views
241 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
336
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Data types vbnet

  1. 1. Data types, Variables and Constants Software Design & Development 1
  2. 2. Data TypesA program can’t do anything until you have reserved aspace in memory for the values used in itThis is called declaration of variablesWhen you declare a variable you must: Give it a sensible name Give it a data type depending on what kind of value it will hold Ask yourself will it hold just letters or whole numbers or numbers with a decimal point or dates…..etc 2
  3. 3. Data typesDepending on the type of data used by our program,we need to choose to use a particular data typeSome programs only use whole numbers – we can’thave ½ a person!Other programs only deal with numbers up to a fewthousand – if we count the students in the CollegeOther programs deal with huge numbers such asdistances in space 3
  4. 4. Basic data typesDate Covers most of the useful range!! Anything from 1st Jan 100 to 31st Dec 9999 Time information is also stored as hours, minutes and seconds Uses 8 bytes of storageString For text e.g. names, addresses, postcodes For numbers that you don’t want to do any maths on e.g. A telephone number You can fix the length or let it be variable Fixing the length also fixes the amount of storage space 4
  5. 5. Basic data typesBoolean For true or false values e.g. Yes / No answers Can be used for numbers  0 = false  Any other value = true Uses 2 bytes of storageDecimal Numbers with decimal places, especially currency Takes 16 bytes of storage 5
  6. 6. Basic data typesShort whole numbers in the range –32,768 to 32,767 Examples: -32 or 10,000 needs 2 bytes of storage spaceInteger A whole number in the range –2 billion to + 2 billion Examples: 20,000,000 or -400,000 needs 4 bytes of storage 6
  7. 7. Basic data typesSingle Numbers with decimal places and fractions in the range -3.402823E38 to –1.401298E-45 for negative values and 1.401298E-45 to 3.4o2823E38 for positive Examples: 3·142, -700·75 Takes 4 bytes of storageDouble For incredibly large or small values use a double, as a single wont provide the range or accuracy that you need Takes 8 bytes of storage Bear this last fact in mind, if you don’t need this level of accuracy, declare a single as it uses half the storage space 7
  8. 8. Variables - Naming conventionsHungarian notation is used in naming variablesThis is accepted as good programming practicePrefix the variable name with a 3 letter identifier toindicate the data typeThe variable name should be meaningful - goodprogrammers can read the code of a program andknow what it doesYou will need to use these conventions 8
  9. 9. VariablesPrefixessht = short dte = dateint = integer dec = decimalsng = single bln = booleandbl = double str = string 9
  10. 10. ConstantsUse a Constant where a value is needed but does notchange while program is running e.g. VAT, Annual Leave, Pi, GravityConstants are always global as they are only set uponceThis allows for easy program modification if valuechangesWe don’t use a Dim statement, but use Const dblPi as double = 3.147 Const sngGravity as single = 9.8 10
  11. 11. Name the variableWrite down some suitable identifiers for thesevariables: VAT Your telephone number Today’s date Whether or not the sun is shining Your name The price of a can of cokeRemember to use naming conventions andcorrect data types! 11

×