1 / 24

Variables Data Types and Assignment

Learn about variables in RAM, data types, and assignment operators. Understand the importance of objects and classes in controlling data. Explore common errors and best practices.

karenbrown
Download Presentation

Variables Data Types and Assignment

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Variables Data Types and Assignment

  2. Stuff to memorise this Week • "A variable is a named section of RAM that stores data of a specific data type"

  3. Objects • In the first lecture we introduced the idea of classes and objects • One way of looking at an object is that it is a word in our code that links to the functions in a class • Once we have an instance of an object (the word) we may access the methods and properties defined in the class • Properties allow us to change or find out about some aspect of the data • Methods allow us to perform some action on the data • There are lots of different objects within the computer system all allowing us to control data in different ways

  4. Screen Objects • Event driven

  5. Presentation (Interface) Middle Tier Business Logic (Objects/Classes) Data Layer Database System Architecture

  6. Layers Split in to Other Layers • Interface and code linked by events

  7. Click Event Handler • Event Handler = Function that responds to an event

  8. Interface v RAM Exercise • Split into two teams • Both teams to count from 1 – 50 • One team to write the numbers on paper • The other team to count in their heads • Everybody stand • Raise your hand when you have finished

  9. The Assignment Operator • The symbol for copying data around the system • Possibly the most important concept in programming • Fail to grasp how this works and you won’t progress

  10. How it works • txtMessage.Text = “Hello world”; • The assignment operator copies data from right to left • Destination = Source • All together now!

  11. Computer Technology • We need objects & classes to control all this!

  12. Where the RAM fits in The RAM

  13. Variables and RAM • Computer RAM is VERY COMPLICATED • Stores data as binary values • “hello” stored as … “0100100001000101010011000100110001001111” • Variables spare us a great deal of pain! • Variables are a very simple kind of object • Allow us to control a section of RAM • Three things we want to do… • Allocate a section of RAM • Give that section a name (a word) • Set the rules for the type of data it will store • Store some data in the variable

  14. Creating Variables • Variables are “declared” using the key word “Dim”

  15. Data Types • Notice in declaring variables we give them a data type, e.g. string • Sets the rule as to the type of data we may put in the box

  16. Data Types • Integer whole number • Types of Int • Int16 -32768 to +32787 • Int32 (or just Int) -2,147,483684 to +2,147,483683 • Int64 -9223372036854775808 to +9223372036854775807 • String any combination of numbers and letters • DateTime any valid date or time • Boolean true or false • Decimal any whole or decimal number

  17. Declare Variables at the top of your code… • Makes them easier to find • Must declare a variable before we may use it

  18. Think as Variables a Boxes in RAM • The seven variables declared above have the following names… ErrMsg OfferTitle Description SwapNo Userno Email UserName • A series of boxes are created…

  19. Rules for Variable Names • We do not have any spaces in the variable names • Err Msg Bad • ErrMsg Good • Use underscore if you want a space e.g. Err_Msg • The variable names use pascal or camel case • swapno Bad • SwapNo Good (public variable) • swapNo Good (private variable) • The names must be meaningful • A, B & C are normally bad names as they give no clue as to their usage

  20. Things we do with Variables • Assign literal constants

  21. Perform Calculations

  22. Get data off the Interface string FirstName; FirstName = txtFirstName.Text;

  23. A Simple Application • To finish off we will create the following application…

  24. Common Variable Errors • We shall look at some common errors in Visual Studio • Learn to recognise the errors • Missing variable declaration • Mismatched Variable Names • Selection of incorrect data type • Rounding errors • Overflow errors

More Related