Presentation is loading. Please wait.

Presentation is loading. Please wait.

U SING V ARIABLES IN V ISUAL B ASIC Intermediate 2 Software Development.

Similar presentations


Presentation on theme: "U SING V ARIABLES IN V ISUAL B ASIC Intermediate 2 Software Development."— Presentation transcript:

1 U SING V ARIABLES IN V ISUAL B ASIC Intermediate 2 Software Development

2 What is a variableWhat is a variable 1 Variable data typesVariable data types 2 Declaring VariablesDeclaring Variables 3 Learning Objectives

3 What is a variable Programs need to be able to store values, either entered by the user, or created as the result of a calculation A variable is a label given to an item of data so that program instructions can work with it.

4 Data Types You learnt in the Computer Systems unit, that computers store different types of data in different ways. It is good programming practice to consider all the data that will need to be stored while the program is running.

5 Data Types We will consider three types of data in this course. – Integers – Single – Strings

6 Declaring Variables Visual BASIC needs to know what type of data it will be storing and processing in any program. To do this, we “declare variables” at the start of the program, using lines like: Dim no_in_class as Integer Dim surname as String Dim price as Single

7 When the VB system “reads” these statements at the start of a program, it sets up a storage space of the appropriate type in the computer’s RAM, and labels it with the variable name given. It is useful to imagine these electronic storage spaces as labelled boxes in which data can be stored, like this …………..

8 An integer variable, called no_in_class, storing value 18. no_in_class 18

9 A string variable, called name, storing value “Gavin”. Name Gavin

10 A single variable, called price,storing value 2.99. price 2.99

11 Variables These “storage boxes” are called variables because the actual value of the data they store can vary or change during the running of a program. It is important to make sure that all variables are correctly declared – the right type (integer, string or single) – and with sensible, readable variable names.

12 Naming Variables Variables can have almost any name, but each variable name: must begin with a letter must not be a VB keyword (like End or Print or MsgBox) must not contain spaces (no_of_pupils is OK, but no of pupils is not).

13 Now do the worked example – pages 53 – 60 in the booklet – “Belinda’s Slab Calculator”


Download ppt "U SING V ARIABLES IN V ISUAL B ASIC Intermediate 2 Software Development."

Similar presentations


Ads by Google