Académique Documents
Professionnel Documents
Culture Documents
Declaring Constants
Some examples:
Const x As Integer = 10
Const PI As Double = 3.14159265
Data Types for Numbers
When working with numbers, we use two types of data:
Integers (usually take the ‘Integer’ type):
Example: 1, 2, 3,…
Useful for ‘discrete’ math:
z counting objects (cardinal)…
z Example: “There were six customers.”
We will talk more about Integers and Floats, and other data
types, shortly…
First, let’s look at some basic mathematical operations.
Mathematical Operators
The table below contains the operators available for basic math
operations:
Program 4.1 - A Simple Calculator
Desired Functionality:
Make a simple program, to implement these operators…
Simple Calculator (cont.)
Simple Calculator (cont.)
Math Statements
In our previous example, we saw a math statement (C = A + B)
Question: what does the statement, ‘x = x + 1’ do’?
Thinking in terms of arithmetic, this is a nonsense statement.
Since ‘=’ is defined as equality…
But x is never equal to x + 1!
However, if we instead think in VB, it makes perfect sense!
Remember…’=’ is the assignment operator.
Thus, ‘x = x + 1’ tells the computer to:
First, get the value stored in variable x.
Then, add 1 to this value.
Lastly, store the result in variable x.
For example, assume x starts out as 10:
Dim x As Integer = 10
x=x+1
During run-time, the right side is first evaluated to yield 11.
Then, this result (11) is passed to the left side (x).
So, the overall result is to set:
z x = 11.
Assignment Operators
Simple one-variable expressions, such as:
n=n+1