VB Introduction 1
VB Introduction 1
1 Introduction
– Procedures
• Indent the entire body of each procedure definition one “level” of
indentation
2002 Prentice Hall.
All rights reserved.
5
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
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)
4 Memory Concepts
• 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
4 Memory Concepts
number1 45
number1 45
number2 45
Fig. 13 Memory locations after values for variables number1 and number2 have been input.
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
5 Arithmetic
45
number1
45
number2
sumOfNumbers 45
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
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.
5 Arithmetic
5 Arithmetic
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
Assembly
containing class
MessageBox
System.Windows.Forms
reference