Sams Teach Yourself Visual Basic 2008 in 24 Hours: Complete Starter Kit

Book description

In just 24 sessions of one hour or less, you will be up and running with Visual Basic 2008. Using a straightforward, step-by-step approach, each lesson builds upon a real-world foundation forged in both technology and business matters, allowing you to learn the essentials of Visual Basic 2008 from the ground up. Step-by-step instructions carefully walk you through the most common questions, issues, and tasks. The Q&A section, quizzes, and exercises help you build and test your knowledge.

By the Way notes present interesting pieces of information. Did You Know? tips offer advice or teach an easier way to do something. Watch Out! cautions advise you about potential problems and help you steer clear of disaster.

Learn how to…

  • Use the powerful design environment of Visual Studio 2008

  • Design feature-rich interfaces using components such as tree views and tabs

  • Create robust applications using modern error-handling

  • Draw fast graphics using GDI+

  • Build a database application using ADO.NET

  • Distribute a Visual Basic 2008 Application

  • Manipulate the Windows Registry

  • Create, read, and write text files

  • Use event-driven techniques to build responsive applications

  • DVD Includes: Microsoft Visual Basic 2008 Express Edition

    On the Web: Register your book at informit.com/title/9780672329845 for access to author code, examples, updates and corrections as they become available.

    Table of contents

    1. Copyright
      1. Dedication
    2. About the Author
    3. Acknowledgments
    4. We Want to Hear from You!
      1. Reader Services
    5. Introduction
      1. Audience and Organization
      2. Conventions Used in This Book
      3. Onward and Upward!
    6. I. The Visual Basic 2008 Environment
      1. 1. Jumping in with Both Feet: A Visual Basic 2008 Programming Tour
        1. Starting Visual Basic 2008
        2. Creating a New Project
        3. Understanding the Visual Studio 2008 Environment
        4. Changing the Characteristics of Objects
          1. Naming Objects
          2. Setting the Text Property of the Form
          3. Saving a Project
          4. Giving the Form an Icon
          5. Changing the Size of the Form
        5. Adding Controls to a Form
        6. Designing an Interface
          1. Adding a Visible Control to a Form
          2. Adding an Invisible Control to a Form
        7. Writing the Code Behind an Interface
          1. Letting a User Browse for a File
          2. Terminating a Program Using Code
        8. Running a Project
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 2. Navigating Visual Basic 2008
        1. Using the Visual Basic 2008 Start Page
          1. Creating New Projects
          2. Opening an Existing Project
        2. Navigating and Customizing the Visual Basic Environment
          1. Working with Design Windows
            1. Showing and Hiding Design Windows
            2. Floating Design Windows
            3. Docking Design Windows
            4. Auto-Hiding Design Windows
        3. Working with Toolbars
          1. Showing and Hiding Toolbars
          2. Docking and Resizing Toolbars
        4. Adding Controls to a Form Using the Toolbox
        5. Setting Object Properties Using the Properties Window
          1. Selecting an Object and Viewing Its Properties
          2. Viewing and Changing Properties
          3. Working with Color Properties
          4. Viewing Property Descriptions
        6. Managing Projects
          1. Managing Project Files with the Solution Explorer
          2. Working with Solutions
          3. Understanding Project Components
          4. Setting Project Properties
          5. Adding and Removing Project Files
        7. A Quick-and-Dirty Programming Primer
          1. Storing Values in Variables
          2. Using Procedures to Write Functional Units of Code
            1. MessageBox.Show()
        8. Getting Help
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 3. Understanding Objects and Collections
        1. Understanding Objects
        2. Understanding Properties
          1. Getting and Setting Properties
          2. Working with an Object and Its Properties
        3. Understanding Methods
          1. Triggering Methods
          2. Understanding Method Dynamism
        4. Building a Simple Object Example Project
          1. Creating the Interface for the Drawing Project
          2. Writing the Object-Based Code
          3. Testing Your Object Example Project
        5. Understanding Collections
        6. Using the Object Browser
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 4. Understanding Events
        1. Understanding Event-Driven Programming
          1. Triggering Events
            1. Events Triggered Through User Interaction
            2. Events Triggered by an Object
            3. Events Triggered by the Operating System
          2. Avoiding Recursive Events
          3. Accessing an Object’s Events
          4. Working with Event Parameters
        2. Building an Event Example Project
          1. Creating the User Interface
          2. Creating Event Handlers
        3. Keeping Event Names Current
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    7. II. Building a User Interface
      1. 5. Building Forms: The Basics
        1. Changing the Name of a Form
        2. Changing the Appearance of a Form
          1. Displaying Text on a Form’s Title Bar
          2. Changing a Form’s Background Color
          3. Adding an Image to a Form’s Background
          4. Giving a Form an Icon
          5. Adding Minimize, Maximize, and Control Box Buttons to a Form
          6. Changing the Appearance and Behavior of a Form’s Border
          7. Controlling a Form’s Minimum and Maximum Size
        3. Showing and Hiding Forms
          1. Showing Forms
          2. Understanding Form Modality
          3. Displaying a Form in a Normal, Maximized, or Minimized State
          4. Specifying a Form’s Initial Display Position
          5. Preventing a Form from Appearing in the Taskbar
          6. Unloading Forms
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 6. Building Forms: Advanced Techniques
        1. Working with Controls
          1. Adding Controls to a Form
            1. Adding a Control by Double-Clicking It in the Toolbox
            2. Adding a Control by Dragging from the Toolbox
            3. Adding a Control by Drawing It
          2. Manipulating Controls
            1. Using the Grid (Size and Snap)
            2. Using Snap Lines
            3. Selecting a Group of Controls
            4. Aligning Controls
            5. Making Controls the Same Size
            6. Evenly Spacing a Group of Controls
            7. Setting Property Values for a Group of Controls
            8. Anchoring and Autosizing Controls
          3. Creating a Tab Order
          4. Layering Controls
        2. Creating Topmost Nonmodal Windows
        3. Creating Transparent Forms
        4. Creating Scrollable Forms
        5. Creating MDI Forms
        6. Setting the Startup Form
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 7. Working with Traditional Controls
        1. Displaying Static Text with the Label Control
        2. Allowing Users to Enter Text Using a Text Box
          1. Specifying Text Alignment
          2. Creating a Multiline Text Box
          3. Adding Scrollbars
          4. Limiting the Number of Characters a User Can Enter
          5. Creating Password Fields
          6. Understanding the Text Box’s Common Events
        3. Creating Buttons
          1. Accept and Cancel Buttons
          2. Presenting Yes/No Options Using Check Boxes
        4. Creating Containers and Groups of Option Buttons
          1. Using Panels and Group Boxes
          2. Working with Radio Buttons
        5. Displaying a List with the List Box
          1. Manipulating Items at Design Time
          2. Manipulating Items at Runtime
            1. Adding Items to a List
            2. Removing Items from a List
            3. Clearing a List
            4. Retrieving Information About the Selected Item in a List
          3. Sorting a List
        6. Creating Drop-Down Lists Using the Combo Box
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 8. Using Advanced Controls
        1. Creating Timers
        2. Creating Tabbed Dialog Boxes
        3. Storing Pictures in an Image List Control
        4. Building Enhanced Lists Using the List View Control
          1. Creating Columns
          2. Adding List Items
          3. Manipulating a List View Using Code
            1. Adding List Items Using Code
            2. Determining the Selected Item in Code
            3. Removing List Items Using Code
            4. Removing All List Items
        5. Creating Hierarchical Lists Using the Tree View Control
          1. Adding Nodes to a Tree View
          2. Removing Nodes
          3. Clearing All Nodes
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      5. 9. Adding Menus and Toolbars to Forms
        1. Building Menus
          1. Creating Top-Level Menus
          2. Creating Menu Items for a Top-Level Menu
          3. Moving and Deleting Menu Items
          4. Creating Checked Menu Items
          5. Programming Menus
          6. Implementing Context Menus
          7. Assigning Shortcut Keys to Menu Items
        2. Using the Toolbar Control
          1. Adding Toolbar Buttons Using the Buttons Collection
          2. Programming Toolbars
          3. Creating Drop-Down Menus for Toolbar Buttons
        3. Creating a Status Bar
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    8. III. Making Things Happen: Programming
      1. 10. Creating and Calling Code Procedures
        1. Creating Visual Basic Code Modules
        2. Writing Code Procedures
          1. Declaring Procedures That Don’t Return Values
          2. Declaring Procedures That Return Values
        3. Calling Code Procedures
          1. Passing Parameters
        4. Exiting Procedures
        5. Avoiding Infinite Recursion
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 11. Using Constants, Data Types, Variables, and Arrays
        1. Understanding Data Types
          1. Determining Data Type
          2. Casting Data from One Data Type to Another
        2. Defining and Using Constants
        3. Declaring and Referencing Variables
          1. Declaring Variables
          2. Passing Literal Values to a Variable
          3. Using Variables in Expressions
          4. Enforced Variable Declaration and Data Typing
          5. Explicit Variable Declaration
          6. Strict Typing
        4. Working with Arrays
          1. Dimensioning Arrays
          2. Referencing Array Variables
          3. Creating Multidimensional Arrays
        5. Determining Scope
          1. Understanding Block Scope
          2. Understanding Procedure-Level (Local) Scope
          3. Understanding Module-Level Scope
          4. Using Global (Namespace) Scope
          5. Scope Name Conflicts
        6. Declaring Variables of Static Scope
        7. Naming Conventions
          1. Using Prefixes to Denote Data Type
          2. Denoting Scope Using Variable Prefixes
          3. Other Prefixes
        8. Using Variables in Your Picture Viewer Project
          1. Creating the Variables for the Options
          2. Initializing and Using the Options Variables
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 12. Performing Arithmetic, String Manipulation, and Date/Time Adjustments
        1. Performing Basic Arithmetic Operations with Visual Basic
          1. Performing Addition
          2. Performing Subtraction and Negation
          3. Performing Multiplication
          4. Performing Division
          5. Performing Exponentiation
          6. Performing Modulus Arithmetic
          7. Determining the Order of Operator Precedence
        2. Comparing Equalities
        3. Understanding Boolean Logic
          1. Using the And Operator
          2. Using the Not Operator
          3. Using the Or Operator
          4. Using the Xor Operator
        4. Manipulating Strings
          1. Concatenating Strings of Text
          2. Using the Basic String Functions
            1. Determining the Number of Characters Using Len()
            2. Retrieving Text from the Left Side of a String Using Microsoft.VisualBasic.Left()
            3. Retrieving Text from the Right Side of a String Using Microsoft.VisualBasic.Right()
            4. Retrieving Text Within a String Using Mid()
            5. Determining Whether One String Contains Another Using Instr()
            6. Trimming Beginning and Trailing Spaces from a String
            7. Replacing Text Within a String
        5. Working with Dates and Times
          1. Understanding the Date Data Type
          2. Adding To or Subtracting From a Date or Time
          3. Determining the Interval Between Two Dates or Times
          4. Retrieving Parts of a Date
          5. Formatting Dates and Times
          6. Retrieving the Current System Date and Time
          7. Determining Whether a Value Is a Date
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 13. Making Decisions in Visual Basic Code
        1. Making Decisions Using If...Then
          1. Executing Code When expression Is False
          2. Using ElseIf for Advanced Decision Making
          3. Nesting If...Then Constructs
        2. Evaluating an Expression for Multiple Values Using Select Case
          1. Evaluating More Than One Possible Value in a Case Statement
          2. Building a Select Case Example
          3. Creative Uses of Select Case
        3. Branching Within a Procedure Using GoTo
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      5. 14. Looping for Efficiency
        1. Looping a Specific Number of Times Using For...Next
          1. Initiating the Loop Using For
          2. Closing the Loop with the Next Statement
          3. Specifying an Increment Value Using Step
          4. Exiting a Loop Early
          5. Continuing Looping Before Next Is Reached
          6. Creating a For...Next Example
        2. Using Do...Loop to Loop an Indeterminate Number of Times
          1. Creating a Do...Loop
          2. Ending a Do...Loop
          3. Creating a Do...Loop Example
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      6. 15. Debugging Your Code
        1. Adding Comments to Your Code
        2. Identifying the Two Basic Types of Errors
        3. Using Visual Basic’s Debugging Tools
          1. Working with Break Points
          2. Using the Immediate Window
        4. Writing an Error Handler Using Try...Catch...Finally
          1. Dealing with an Exception
          2. Handling an Anticipated Exception
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      7. 16. Designing Objects Using Classes
        1. Understanding Classes
          1. Encapsulating Data and Code Using Classes
          2. Comparing Classes with Standard Modules
          3. Creating an Object Interface
            1. Exposing Object Attributes as Properties
              1. Creating Readable Properties Using the Get Construct
              2. Creating Writable Properties Using the Set Construct
              3. Creating Read-Only or Write-Only Properties
            2. Exposing Functions as Methods
        2. Instantiating Objects from Classes
          1. Binding an Object Reference to a Variable
            1. Late-Binding an Object Variable
            2. Early-Binding an Object Variable
            3. Creating a New Object When Dimensioning a Variable
          2. Releasing Object References
          3. Understanding the Lifetime of an Object
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      8. 17. Interacting with Users
        1. Displaying Messages Using the MessageBox.Show() Function
          1. Specifying Buttons and an Icon
          2. Determining Which Button Is Clicked
          3. Creating Good Messages
        2. Creating Custom Dialog Boxes
        3. Using InputBox() to Get Information from a User
        4. Interacting with the Keyboard
        5. Using the Common Mouse Events
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    9. IV. Working with Data
      1. 18. Working with Graphics
        1. Understanding the Graphics Object
          1. Creating a Graphics Object for a Form or Control
          2. Creating a Graphics Object for a New Bitmap
        2. Working with Pens
        3. Using System Colors
        4. Working with Rectangles
        5. Drawing Shapes
          1. Drawing Lines
          2. Drawing Rectangles
          3. Drawing Circles and Ellipses
          4. Clearing a Drawing Surface
        6. Drawing Text
        7. Persisting Graphics on a Form
        8. Building a Graphics Project Example
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 19. Performing File Operations
        1. Using the OpenFileDialog and SaveFileDialog Controls
          1. Using the OpenFileDialog Control
            1. Creating File Filters
            2. Showing the Open File Dialog Box
          2. Using the SaveFileDialog Control
        2. Manipulating Files with the File Object
          1. Determining Whether a File Exists
          2. Copying a File
          3. Moving a File
          4. Renaming a File
          5. Deleting a File
          6. Retrieving a File’s Properties
            1. Getting Date and Time Information About a File
            2. Getting a File’s Attributes
            3. Writing Code to Retrieve a File’s Properties
        3. Manipulating Directories with the Directory Object
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      3. 20. Working with Text Files and the Registry
        1. Working with the Registry
          1. Understanding the Structure of the Windows Registry
          2. Accessing the Registry with My.Computer.Registry
            1. Creating Registry Keys
            2. Deleting Registry Keys
            3. Getting and Setting Key Values
          3. Modifying Your Picture Viewer Project to Use the Registry
            1. Displaying Options from the Registry
            2. Saving Options to the Registry
            3. Using the Options Stored in the Registry
            4. Testing and Debugging Your Picture Viewer Project
        2. Reading and Writing Text Files
          1. Writing to a Text File
          2. Reading a Text File
          3. Modifying Your Picture Viewer Project to Use a Text File
            1. Creating the Picture Viewer Log File
            2. Displaying the Picture Viewer Log File
            3. Testing Your Picture Viewer Log
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      4. 21. Working with a Database
        1. Introducing ADO.NET
          1. Connecting to a Database
          2. Closing a Connection to a Data Source
        2. Manipulating Data
          1. Understanding DataTables
          2. Creating a DataAdapter
          3. Creating and Populating DataTables
          4. Referencing Fields in a DataRow
          5. Navigating Records
          6. Editing Records
          7. Creating New Records
          8. Deleting Records
          9. Running the Database Example
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      5. 22. Controlling Other Applications Using Automation
        1. Creating a Reference to an Automation Library
        2. Creating an Instance of an Automation Server
        3. Manipulating the Server
          1. Forcing Excel to Show Itself
          2. Creating an Excel Workbook
          3. Working with Data in an Excel Workbook
          4. Testing Your Client Application
        4. Automating Microsoft Word
          1. Creating a Reference to an Automation Library
          2. Creating an Instance of an Automation Server
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
          3. Exercises
    10. V. Deploying Solutions and Beyond
      1. 23. Deploying Applications
        1. Understanding ClickOnce Technology
        2. Using the Publish Wizard to Create a ClickOnce Application
        3. Testing Your Picture Viewer ClickOnce Install Program
        4. Uninstalling an Application You’ve Distributed
        5. Setting Advanced Options for Creating ClickOnce Programs
        6. Summary
        7. Q&A
        8. Workshop
          1. Quiz
          2. Answers
          3. Exercises
      2. 24. The 10,000-Foot View
        1. The .NET Framework
        2. Common Language Runtime
        3. Microsoft Intermediate Language
        4. Namespaces
        5. Common Type System
        6. Garbage Collection
        7. Further Reading
        8. Summary

    Product information

    • Title: Sams Teach Yourself Visual Basic 2008 in 24 Hours: Complete Starter Kit
    • Author(s):
    • Release date: May 2008
    • Publisher(s): Sams
    • ISBN: 9780768678468