Table of
Contents
Learn to Program with VB.Net 2002/2003
CHAPTER 1---WHERE DO I BEGIN?
WHERE DO WE BEGIN
PROGRAMMING THE EASY WAY
PLANNING A PROGRAM IS LIKE PLANNING A HOUSE
WE RECEIVE A CALL FROM THE CHINA SHOP
WE MEET WITH OUR CLIENT
THE SYSTEMS DEVELOPMENT LIFE CYCLE (SDLC)
PHASE 1: THE PRELIMINARY INVESTIGATION
PHASE 2: ANALYSIS
PHASE 3: DESIGN
Output Design
Input Design
Processing Design
PHASE 4: DEVELOPMENT
PHASE 5: IMPLEMENTATION
PHASE 6: AUDIT AND MAINTENANCE
WHERE TO FROM HERE?
SUMMARY
CHAPTER 2---WHAT IS A COMPUTER PROGRAM?
WHAT IS A COMPUTER?
DATA
Bits
Bytes
MEMORY
COMPUTER STORAGE
RAM VERSUS STORAGE
WHAT MAKES A COMPUTER PROGRAM RUN?
A LITTLE COMPUTER HISTORY
DOS
Booting DOS
Running Programs in DOS
C:\>WP
Bad Command or File name
RAM Use in DOS
Registers
The Stack
Problems with DOS
MICROSOFT WINDOWS
The Title Bar
The Menu Bar
Windows Behavior
A MORE IN-DEPTH LOOK AT WINDOWS
Virtual Memory
MULTITASKING
Nonpreemptive Multitasking
Preemptive Multitasking
Running Programs in Windows
Preparing the Windows Program to Run
Running the Windows Program
The Windows Handle
Windows Messages
The Focus
WHAT IS A COMPUTER PROGRAM?
SUMMARY
CHAPTER 3---GETTING COMFORTABLE WITH VISUAL BASIC
THE VISUAL BASIC ENVIRONMENT
PREPARING THE WAY FOR PROGRAMMING
LET’S START UP VISUAL BASIC!
THE VISUAL BASIC PROJECT
THE IDE
THE MODES OF VISUAL BASIC
THE VISUAL BASIC MENU BAR
The File Menu
The Print Menu
The Edit Menu
The View Menu
The Project Menu
The Build Menu
The Debug Menu
The Data Menu
The Format Menu
The Tools Menu
The Window Menu
The Help Menu
THE VISUAL BASIC TOOLBAR
THE VISUAL BASIC TOOLBOX
THE PROPERTIES WINDOW
SUMMARY
CHAPTER 4---PROGRAMMING IS EASY
LESS IS BEST
VISUAL BASIC PROPERTIES, METHODS, AND EVENTS
VISUAL BASIC PROPERTIES
RUNNING THE CHINA SHOP PROJECT FOR THE FIRST TIME
PROPERTIES OF THE FORM
Name of the Form
Naming Conventions
Height and Width Properties
The FormBorderStyle and ControlBox Properties
The StartPosition Property
The Text Property
VISUAL BASIC METHODS
VISUAL BASIC EVENTS
SUMMARY
CHAPTER 5---BUILDING THE USER INTERFACE
COMPLETING THE USER INTERFACE
JOHN SMILEY’S TEN-STEP GUIDE TO SUCCESSFUL INTERFACE DEVELOPMENT
THE VISUAL BASIC TOOLBOX
THE CHINA SHOP CONTROLS
CREATION OF THE CHINA SHOP FORM
The GroupBox Control
The ListBox Control
The Label Control
The Button Control
The CheckBox Control
The RadioButton Control
The PictureBox Control
The ColorDialog Control
The Timer Control
LET’S RUN THE CHINA SHOP PROJECT!
COMMON PROPERTIES OF THE CONTROLS IN THE CHINA SHOP PROJECT
The Name Property
The Text Property
CHECKBOX PROPERTIES
BUTTON CONTROL PROPERTIES
The AcceptButton Property of the Form
The CancelButton Property of the Form
COLORDIALOG PROPERTIES
GROUPBOX PROPERTIES
PICTUREBOX CONTROL PROPERTIES
The SizeMode Property
LABEL PROPERTIES
The AutoSize Property
LISTBOX PROPERTIES
RADIOBUTTON PROPERTIES
TIMER PROPERTIES
The Interval Property
TAB ORDER AND THE TABINDEX PROPERTY
A SURPRISE VISIT
SUMMARY
CHAPTER 6---A FIRST LOOK AT CODING
EVENTS AND EVENT-DRIVEN PROGRAMMING
IN THE OLD DAYS...
THE MODERN APPROACH
WHAT’S AN EVENT?
An Event or an Event Procedure?
An Example of an Event Procedure Stub
THE EVENTS IN THE CHINA SHOP PROJECT
The Click Event
The Load Event
The SelectedIndexChanged Event
The Tick Event
WRITING CODE
PROGRAM COMMENTS
THE LINE CONTINUATION CHARACTER (_)
A VISUAL BASIC CODE OVERVIEW
The Sequence Structure—Falling Rock
The Selection Structure
The Loop Structure
Console.Writeline()
THE VISUAL BASIC DEBUGGER
The Debug/Immediate Window
Pausing a Visual Basic Program
The Break Button
Displaying Values in the Code Window
The Command Window
The Stop Statement
THE DEBUG MENU
Step Into
Run To Cursor
Step Over
Step Out
Set Next Statement
Show Next Statement
The Locals Window
The Autos Window
The Me Window
The Watch Window
Breakpoints
SUMMARY
CHAPTER 7---DATA
COMPUTER DATA
VARIABLES
HOW DO WE CREATE A VARIABLE?
VARIABLE DECLARATION
The Dim Statement
Declaring More than One Variable with one line of code
Variable Scope
The Private Statement
The Public Statement
Where Should You Declare a Variable?
MUST VARIABLES BE INITIALIZED?
VISUAL BASIC DATA TYPES
NUMERIC DATA TYPES
Byte
Char
Short
Integer
Long
Single
Double
Decimal
THE STRING DATA TYPE
OTHER DATA TYPES
Boolean
Date
PROPERTY DATA TYPES
CONSTANTS
OPERATIONS ON DATA
ARITHMETIC OPERATIONS
The Addition Operator
The Subtraction Operator
The Multiplication Operator
The Integer Division Operator
The Floating-Point Division Operator
The Mod Operator
The Exponentiation Operator
Order of Operations
COMPARISON OPERATORS
LOGICAL OPERATORS
The And Operator
The Or Operator
The Not Operator
How Not to Use Not
SUMMARY
CHAPTER 8---SELECTION STRUCTURES
FALLING ROCK BEHAVIOR
HOW CAN WE IMPROVE UPON THIS?
IF…THEN
IF…THEN…ELSE
IF…THEN…ELSEIF
SELECT...CASE
THE CHINA SHOP PROJECT
REVIEWING THE PROTOTYPE
SUMMARY
CHAPTER 9---LOOPS
WHY LOOPS?
THE FOR...NEXT LOOP
Variations on the For...Next Theme
DO...LOOPS
Do While...Loop
Do...Loop While
Do Until...Loop
Discussion
Do...Loop Until
MR. BULLINA SENDS A SURPRISE
SUMMARY
CHAPTER 10---STRING MANIPULATION
WHAT EXACTLY IS A STRING?
STRING CONCATENATION
BREAKING STRINGS APART
SUMMARY
CHAPTER 11---FILE OPERATIONS
DISK FILE OPERATIONS
WRITING DATA TO A DISK FILE
The FileOpen Statement
The WriteLine Statement
The FileClose Statement
READING DATA FROM A DISK FILE
The Input Statement
SUMMARY
CHAPTER 12---FINISHING THE USER INTERFACE
WHERE ARE WE NOW?
DROP-DOWN MENUS
A FIRST LOOK AT THE MAIN MENU CONTROL
Adding Top-Level Menu Items
Adding Submenu Items
Deleting Menu Items
Inserting Menu Items
MenuItem Properties
Menu Item Events
CODING THE MENU CONTROL
MORE ON THE MSGBOX FUNCTION
THE RETURN VALUE OF THE MSGBOX FUNCTION
THE BUTTON ARGUMENT OF THE MSGBOX FUNCTION
SUMMARY
CHAPTER 13---ARRAYS
WHY ARRAYS?
WHAT’S AN ARRAY?
Declaring an Array
Referring to Elements of an Array
DYNAMIC ARRAYS
ARRAY DIMENSIONS
MODIFYING THE CHINA SHOP PROJECT TO INCLUDE ARRAYS
SUMMARY
CHAPTER 14---ERROR HANDLING
COMMON BEGINNER ERRORS
FORGETTING TO INCREMENT A COUNTER VARIABLE
FORGETTING TO ADD TO AN ACCUMULATOR
FORGETTING TO OPEN A FILE
OPENING A FILE THAT’S ALREADY OPEN
FORGETTING TO CLOSE A FILE
READING BEYOND THE END OF THE FILE
WRITING TO A FILE OPENED FOR INPUT
YOUR PROGRAM DOESN’T FIND ANY RECORDS
THE FILE YOU ARE READING IS MISSING OR EMPTY
READING TOO MANY OR TOO FEW FIELDS FROM A DISK FILE
DIVISION BY ZERO
ERROR HANDLING
UNSTRUCTURED ERROR HANDLING: ON ERROR GOTO
STRUCTURED ERROR HANDLING: TRY AND CATCH
ERROR HANDLING IN THE CHINA SHOP PROJECT
SUMMARY
CHAPTER 15---CUSTOMIZING YOUR PROGRAM
WRITING TO THE WINDOWS REGISTRY
GETSETTING AND SAVESETTING
USING REGEDIT
READING FROM THE WINDOWS REGISTRY
OPTIMIZING VISUAL BASIC CODE
USER-WRITTEN PROCEDURES
Writing Our Own Procedures
SUBPROCEDURES IN THE CHINA SHOP PROJECT
TESTING OUR PROGRAM
WE MEET AT THE BULLINA CHINA SHOP
SUMMARY