180 likes | 330 Views
VB02. Programming Concepts Variables. Variables. 23. Variables are virtual boxes that hold pieces of information Variables are referred to by their names. Age. Variable Types. There are different types of variables Different types of variable boxes hold differet types of data.
E N D
VB02 Programming Concepts Variables
Variables 23 • Variables are virtual boxes that hold pieces of information • Variables are referred to by their names Age
Variable Types • There are different types of variables • Different types of variable boxes hold differet types of data
Variable Types 37.56 • Some variables hold number • Some variables hold letters 21 “Robert” price Vat rate name
Boolean Byte Currency Date Decimal Double Integer Long Object Single String Variant Visual Basic Variable Types
Variable Names • In general you can call variables whatever you like • Most programming languages have restrictions on the names (e.g.must start with a letter) • VB recommend prefixes for variable names to make life easier
Boolean bln Byte byt Currency cur Date dte Decimal Double dbl Integer int Long lng Object obj Single sng String str Variant vnt or var Visual Basic Variable Type Prefixes (by convention)
Boolean • Named after George Boole • Can hold TRUE or FALSE • That’s all! • E.g. blnLight
Byte • Positive number between 0 and 255 • e.g. bytNumStudents • e.g. 36 • e.g.0 • e.g. 200 102
Integer • Whoel number between –32768 and 32767 • Not decimals • e.g. intNumCars • e.g. 9346 • e.g. –703 • e.g. 32000 21056
Long • Whole number between –2147483648 and 2147483647 • e.g. lngNumPeople • 2 000 000 067 • -2 000 000 000 • 45 • -6 2836475
Decimal • Numbers with 28 decimal places • Limited support for this type in VB • Best to use Single instead • e.g. 35.5768455465 • e.g. 7.57846354869 12.457
Currency • Money amounts from -$922 337 203 685 477.5808 to $922 337 203 685 477.5807 • e.g. curLotto • Used exclusively for money • VB looks after the formatting based on local currency settings
Single • Numeric value from -3.402823E+38 to 3.402823E+38 • Decimal numbers in scientific notation • e.g. sngAtomMass
Date • Date & Time value from 1 Jan 0100 to 31 Dec 9999 • In a variety of formats • e.g. dteBirthday • VB looks after the formatting based on local preferences • e.g. 22:35 17 Jan 2002
Double • Just like single only more precice • Allows for bigger numbers • -1.76769313486232E+308 to 1.76769313486232E+308 • e.g. dblElectronMass
String • Used to store characters (letters, numbers, symbols) • Up to 65 400 characters • Usually enclosed in quotes • e.g. strName • e.g. “Hello!” • e.g. “Cork” España ¡Hola! 1271 Rossa Ave.
Variant • Used to hold things when you don’t kow what hey are • Usually a bad idea • You should knw • We won’t use this type in this course