Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
41 views

Programming Notes 3

Uploaded by

Long Le
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Programming Notes 3

Uploaded by

Long Le
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data types

An attribute which tells the computer or interpreter how the programmer intends to use
data.
Byte
- An integer between 0 and 255
Integer
- A numeric value, used to represent whole numbers (no fractional part)
- Fractional data is lost when stored as integers.
Decimals
- Numbers that include a fractional or decimal part
Double – Floating point
- For storing large numbers especially decimals
- Has a precision of 15 decimal places
Character
- Used to hold a single letter, number or symbol
Strings – text
- Common type of variable
- Sequence of characters
- Can be a whole word or sentence/s or as individual characters
- A string length can contain a maximum of 255 characters
- Various characters (numbers, letters, punctuation, etc) that we “string” together for
display
- Numbers can be stored as string but cannot be used for calculations in that form
- Use strings to store phone numbers (03) 9397 8909 as strings can hold parentheses,
leading zeros and spaces while numeric data types cannot
Boolean data (true/false)
- Stores one of two values – true or false
- A Boolean always defaults to false and doesn’t change until your code tells it to
Date and time
- Not recorded as the actual date or time (0:00:00am 1/1/01 to 11:59:59pm
12/31/9999
- The date is held in the form of an integer that counts the numbers of days from a
specified reference point, such as 1900 and time data is stored as a decimal fraction
of the day
Currency
- Numeric, for strong monetary values only
- It has a large number of decimal places to prevent rounding errors

Elements of programming
Algorithm
- Specifies a series of steps that perform a particular computation or tasks
- Algorithm resembles recipes
- Recipes tell you how to accomplish a task by performing a number of steps
- Preheat the oven, mix flour, add sugar, beat eggs, pour into baking pan, etc.
- Algorithm is an unambiguous description that makes clear what has to be
implemented.
- In a recipe, “bake until done” is ambiguous because it doesn’t explain what “done”
means
- In a computational algorithm, a step such as “Choose a large number” is vague:
what is large? 1, 1 million, 1 billion, or 100?
- Algorithm expects a defined set of inputs
- Might require two numbers where both numbers are greater than zero
- Algorithm produces a defined set of outputs
- It might output the larger of the two numbers

Variables
- A variable is a piece of data that can change its value during the course of a
program’s execution
- Variables are used to store values that are needed for a program to run successfully.
- Before you can use a variable in a program you need to declare it.
- This means you need to tell the computer that you are going to use a particular
data type – this enables the computer to know how much memory it needs to set
aside to store this value

Dim [Variable Name] As [Data Type]


Dim [Variable Name] As [Data Type] = [Value]

Item Description
Dim To declare and allocate the storage space
for one or more variables
[Variable Name] It’s the name of the variable to hold the
values in our application
As The As clause in the declaration statement
allows you to define the data type
[Data Type] It’s a type of data the variable can hold
such as integer, string, decimal, etc.
[Value] Assigning a required value to the variable.

Rules and conventions for Naming Variables


- Must be unique
- Must start with a alphabetic character (A-Z)
- Must only contain a-z,0-9 and underscore (no spaces or other punctuation)
- Should be meaningful
- Dim w As Integer = 7
- Dim roomWidth_int As Integer = 7
- Use camel case – when joining two or more words to make a meaningful variable
name, start with lowercase, remove whitespace between works and subsequent
words start with upper case:
- Dim totalheightofbuilding As Double = 34.67
- Dim totalBuildingHeight As Double = 34.67

You might also like