Chapter03 PPT
Chapter03 PPT
3.1 Introduction
– Procedures
• Indent the entire body of each procedure definition one “level” of
indentation
2002 Prentice Hall.
All rights reserved.
5
3.2 Simple Program: Printing a Line
of Text
• Now a short step-by-step explanation of how to
create and run this program using the features of
Visual Studio .NET IDE…
Project
name
File
location
Fig. 3.2 Creating a Console Application with the New Project dialog.
Solution Explorer
Click Module1.vb
to display its
properties
Properties window
File
Name
property
Description of
highlighted member
Blue underline
indicates a
syntax error
Error description(s)
• Variables
– correspond to actual locations in the computer’s memory
– Every variable has a
• Name
• Type
• Size
• value
– A value placed in a memory location replaces the value
previously stored
• The previous value is destroyed
– When value is read from a memory location, it is not
destroyed
number1 45
Fig. 3.12 Memory location showing name and value of variable number1.
number1 45
number2 45
Fig. 3.13 Memory locations after values for variables number1 and number2 have been input.
3.5 Arithmetic
• Arithmetic operators
– Visual Basic use various special symbols not used in algebra
• Asterisk (*), keyword Mod
– Binary operators
• Operates using two operands
– sum + value
– Unary operators
• Operators that take only one operand
– +9, -19
3.5 Arithmetic
45
number1
45
number2
sumOfNumbers 45
3.5 Arithmetic
• Integer division
– Uses the backslash, \
– 7 \ 4 evaluates to 1
• Floating-point division
– Uses the forward slash, /
– 7 / 4 evaluates to 1.75
• Modulus operator, Mod
– Yields the remainder after Integer division
– 7 Mod 4 yields 3
3.5 Arithmetic
x y
Division (Integer) \ none v \ u
Modulus % r mod s r Mod s
qp
q
Exponentiation ^ ^p
Unary Negative - –e –e
Unary Positive + +g +g
Fig. 3.14 Arithmetic operators.
3.5 Arithmetic
3.5 Arithmetic
3.5 Arithmetic
Step 1. y = 2 * 5 * 5 + 3 * 5 + 7
2 * 5 is 10 (Leftmost multiplication)
Step 2. y = 10 * 5 + 3 * 5 + 7
10 * 5 is 50 (Leftmost multiplication)
Step 3. y = 50 + 3 * 5 + 7
3 * 5 is 15 (Multiplication before addition)
Step 4. y = 50 + 15 + 7
50 + 15 is 65 (Leftmost addition)
Step 5. y = 65 + 7
65 + 7 is 72 (Last addition)
Relational
operators
> > x > y x is greater than y
< < x < y x is less than y
>= x >= y x is greater than or equal to y
? <= x <= y x is less than or equal to y
Fig. 3.17 Equality and relational operators.
Program Output
Empty command
window
Title bar
Dialog sized to
accommodate Close
contents. box
OK button allows
the user to Mouse pointer
dismiss the
dialog.
Search
string
Filte
r Link to MessageBox
documentation
Fig. 3.22 Obtaining documentation for a class by using the Index dialog.
Assembly
containing class
MessageBox
System.Windows.Forms
reference
Fig. 3.24 Adding a reference to an assembly in the Visual Studio .NET IDE.
2002 Prentice Hall. All rights reserved.
43
3.7 Using a Dialog to Display a
Message
Button
Label (displaying an Menu (e.g., Help) Text Menu bar
icon) box