2002 Prentice Hall. All Rights Reserved
2002 Prentice Hall. All Rights Reserved
3.1 Introduction
– Procedures
• Indent the entire body of each procedure definition one “level” of
indentation
2002 Prentice Hall.
All rights reserved.
5
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
xy
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 Arith m e tic o p e ra to rs.
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 Eq u a lity a n d re la tio n a l o p e ra to rs.
• Dialogs
– Windows that typically display messages to the user
– Visual Basic provides class MessageBox for creating
dialogs
Program Output
Empty command
window
Title bar
Dialog sized to
accommodate Close box
contents.
• Assembly
– File that contain many classes provided by Visual Basic
– These files have a .dll (or dynamic link library) extension.
– Example
• Class MessageBox is located in assembly
System.Windows.Forms.dll
• MSDN Documentation
– Information about the assembly that we need can be found in
the MSDN documentation
– Select Help > Index… to display the Index dialog
Search string
Filter
Link to MessageBox
documentation
Fig. 3.22 Obtaining documentation for a class by using the Index dialog.
Assembly containing
class MessageBox
• Reference
– It is necessary to add a reference to the assembly if you wish
to use its classes
– Example
• To use class MessageBox it is necessary to add a reference
to System.Windows.Forms
• Imports
– Forgetting to add an Imports statement for a referenced
assembly is a syntax error
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