Visual Basic 2015 in 24 Hours, Sams Teach Yourself

Book description

In just 24 sessions of one hour or less, you’ll learn how to build complete, reliable, and modern Windows applications with Microsoft® Visual Basic® 2015. Using a straightforward, step-by-step approach, each lesson builds on what you’ve already learned, giving you a strong foundation for success with every aspect of VB 2015 development.

Notes present interesting pieces of information.

Tips offer advice or teach an easier way to do something.

Cautions advise you about potential problems and help you steer clear of disaster.

Learn How To

  • Master VB 2015 by building a complete feature-rich application

  • Navigate VB 2015 and discover its new shortcuts

  • Work with objects, collections, and events

  • Build attractive, highly-functional user interfaces

  • Make the most of forms, controls, modules, and procedures

  • Efficiently store data and program databases

  • Make decisions in code

  • Use powerful object-oriented techniques

  • Work with graphics and text files

  • Manipulate filesystems and the Registry

  • Add email support

  • Create efficient modules and reusable procedures

  • Interact effectively with users

  • Write code to preview and print documents

  • Debug with VB 2015’s improved breakpoint features

  • Distribute your software

  • Download all examples and source code presented in this book from informit.com/title/9780672337451 as they become available.

    Who Should Read This Book

    Those who have little or no programming experience or who might be picking up Visual Basic as a second language.

    Bug Alert

    Description: Changing the startup form's name in a VB WinForms app does not update the "Startup form" #4517

    Explanation: In the latest Visual Basic update on GitHub, Microsoft accidentally introduced a significant bug that you should be aware of. In the Visual Basic project properties dialog on one of the tabs (Application), is a drop down box for selecting the "startup object". This can be either a Main method or a System.Windows.Forms instance (or System.Windows.Window for WPF). When you do a rename on a form (say from the code editor in source or from the solution explorer) currently set as the startup form the rename doesn't cascade to the startup object project property cause the project to enter an invalid state where the user must now manually reset this project property from the now nonexistent Form to the new name. This is a huge annoyance.

    The fix for the bug (until Microsoft addresses) can be found here:
    http://www.jamesfoxall.com/teach-visual-basic-2015-errata/

    Table of contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Contents at a Glance
    5. Table of Contents
    6. About the Author
    7. Dedication
    8. Acknowledgments
    9. We Want to Hear from You!
    10. Reader Services
    11. Introduction
      1. Audience and Organization
      2. Conventions Used in This Book
      3. Onward and Upward!
    12. Part I: The Visual Basic 2015 Environment
      1. Hour 1. Jumping in with Both Feet: A Visual Basic 2015 Programming Tour
        1. Starting Visual Basic 2015
        2. Creating a New Project
        3. Understanding the Visual Studio 2015 Environment
        4. Changing the Characteristics of Objects
          1. Naming Objects
          2. Setting the Form’s Text Property
          3. Saving a Project
          4. Giving the Form an Icon
          5. Changing the Form’s Size
        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
        12. Exercises
      2. Hour 2. Navigating Visual Basic 2015
        1. Using the Visual Basic 2015 Start Page
          1. Creating New Projects
          2. Opening an Existing Project
        2. Navigating and Customizing the Visual Basic Environment
          1. Working with Design Windows
        3. Working with Toolbars
          1. Showing and Hiding 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
          3. MessageBox.Show()
        8. Getting Help
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
        12. Exercises
      3. Hour 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
        10. Exercises
      4. Hour 4. Understanding Events
        1. Understanding Event-Driven Programming
          1. Triggering Events
          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
        7. Exercises
    13. Part II: Building a User Interface
      1. Hour 5. Building Forms: The Basics
        1. Changing a Form’s Name
        2. Changing a Form’s Appearance
          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 on the Taskbar
          6. Unloading Forms
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
        7. Exercises
      2. Hour 6. Building Forms: Advanced Techniques
        1. Working with Controls
          1. Adding Controls to a Form
          2. Manipulating 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
        10. Exercises
      3. Hour 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
          3. Sorting a List
        6. Creating Drop-Down Lists Using the Combo Box
        7. Summary
        8. Q&A
        9. Workshop
          1. Quiz
          2. Answers
        10. Exercises
      4. Hour 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
        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
        9. Exercises
      5. Hour 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 Items 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
        7. Exercises
    14. Part III: Making Things Happen—Programming
      1. Hour 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
        9. Exercises
      2. Hour 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. Using Variables in Your Picture Viewer Project
          1. Creating the Variables for the Options
          2. Initializing and Using the Options Variables
        8. Renaming Variables
        9. Summary
        10. Q&A
        11. Workshop
          1. Quiz
          2. Answers
        12. Exercises
      3. Hour 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
        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
        9. Exercises
      4. Hour 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
          4. Evaluating More Than One Possible Value in a Case Statement
          5. Building a Select Case Example
          6. Creative Uses of Select Case
        2. Branching Within a Procedure Using GoTo
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
        6. Exercises
      5. Hour 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
        6. Exercises
      6. Hour 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 Breakpoints
          2. Using the Immediate Window
          3. Using Advanced Breakpoint Features
        4. Breaking Only When a Condition Is Met
        5. Breaking Only When a Breakpoint Is Hit a Certain Number of Times
        6. Sending Messages to the Output Window Using Tracepoints
        7. Writing an Error Handler Using Try...Catch...Finally
          1. Dealing with an Exception
          2. Handling an Anticipated Exception
        8. Summary
        9. Q&A
        10. Workshop
          1. Quiz
          2. Answers
        11. Exercises
      7. Hour 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
        2. Instantiating Objects from Classes
          1. Binding an Object Reference to a Variable
          2. Releasing Object References
          3. Understanding the Lifetime of an Object
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
        6. Exercises
      8. Hour 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
        9. Exercises
      9. Hour 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
        12. Exercises
    15. Part IV: Working with Data
      1. Hour 19. Performing File Operations
        1. Using the OpenFileDialog and SaveFileDialog Controls
          1. Using the OpenFileDialog Control
          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
        3. Manipulating Directories with the Directory Object
        4. Summary
        5. Q&A
        6. Workshop
          1. Quiz
          2. Answers
        7. Exercises
      2. Hour 20. Working with the Registry and Text Files
        1. Working with the Registry
          1. Understanding the Structure of the Windows Registry
          2. Accessing the Registry with My.Computer.Registry
          3. Modifying Your Picture Viewer Project to Use the Registry
        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
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
        6. Exercises
      3. Hour 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
        6. Exercises
      4. Hour 22. Printing
        1. Preparing the Picture Viewer Project
          1. Adding Print and Print Preview Buttons to the Form
          2. Adding the PrintDocument, PrintPreviewDialog, and PageSetupDialog Controls
        2. Printing and Previewing a Document
          1. Printing a Document
          2. Previewing a Document
        3. Changing Printer and Page Settings
        4. Scaling Images to Fit a Page
        5. Summary
        6. Q&A
        7. Workshop
          1. Quiz
          2. Answers
        8. Exercises
      5. Hour 23. Sending Emails
        1. Understanding the Classes Used to Send Emails
        2. Sending Email from Your Picture Viewer Application
          1. Adding a Send Email Toolbar Button
          2. Creating the Send Email Dialog Box
          3. Writing Code to Send Emails
          4. Testing Your Email Code
        3. Summary
        4. Q&A
        5. Workshop
          1. Quiz
          2. Answers
        6. Exercises
    16. Part V: Deploying Solutions and Beyond
      1. Hour 24. 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
        9. Exercises
    17. Appendix A. 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
    18. Index
    19. Code Snippets

    Product information

    • Title: Visual Basic 2015 in 24 Hours, Sams Teach Yourself
    • Author(s):
    • Release date: August 2015
    • Publisher(s): Sams
    • ISBN: 9780134191874