You are previewing Visual Basic® 2012 Unleashed, Second Edition.
O'Reilly logo
Visual Basic® 2012 Unleashed, Second Edition

Book Description

Fully updated for Windows 8 support, .NET 4.5, and Windows Phone development, this is the most comprehensive, practical reference to modern programming with Visual Basic 2012. Written by Visual Basic MVP Alessandro Del Sole, a long-time leader of the global VB community, this book illuminates the core of the VB language and demonstrates its effective use in many current programming scenarios.

Del Sole covers both Visual Basic 2012 Professional Edition for professional developers and the Express Edition for hobbyists, novices, and students. Writing for VB programmers at all levels of experience, he walks through using VB 2012 for data access, Windows desktop/Windows Phone user interface development, networking, communication, and much more.

For those moving from structured languages—including VB 6—Del Sole offers detailed guidance on building effective object-oriented code. He also demonstrates how to make the most of Microsoft’s updated .NET 4.5 platform to write more robust and powerful software.

Detailed information on how to…

¿ Understand the Visual Studio 2012 IDE, .NET Framework 4.5, and the anatomy of a VB 2012 application

¿ Debug VB applications and implement error handling and exceptions

¿ Build efficient object-oriented software with classes, objects, namespaces, and inheritance

¿ Work with advanced object-oriented features, including interfaces, generics, delegates, events, and collections

¿ Access data with LINQ—including LINQ to Objects, SQL, DataSets, Entities, XML, and Parallel LINQ

¿ Build modern Windows applications with WPF

¿ Develop web-centric applications using ASP.NET, Silverlight 5, and Windows Azure Services cloud computing

¿ Use advanced .NET 4.5 platform capabilities, including asynchronous programming, multithreading, parallel programming

¿ Build apps for Windows Phone

¿ Test code with unit tests, TDD, and code contracts

¿ Deploy apps efficiently with InstallShield for Visual Studio and ClickOnce

Table of Contents

  1. Title Page
  2. Copyright Page
  3. Contents at a Glance
  4. Table of Contents
  5. Foreword
  6. About the Author
  7. Dedication
  8. Acknowledgments
  9. We Want to Hear from You!
  10. Reader Services
  11. Part I: Learning the Basics of VB
    1. Chapter 1. Introducing the .NET Framework 4.5
      1. What Is the .NET Framework?
      2. The Common Language Runtime
      3. The Base Class Library
      4. Programming Languages Included in .NET 4.5
      5. Additional Tools Shipping with the .NET Framework
      6. What’s New in .NET Framework 4.5
      7. How .NET Meets Windows 8 and the Windows Runtime
      8. Summary
    2. Chapter 2. Getting Started with the Visual Studio 2012 IDE
      1. What’s New in Visual Studio 2012
      2. Status Bar and Start Page
      3. Working with Projects and Solutions
      4. Working with Tool Windows
      5. My Project
      6. Compiling Projects
      7. Debugging Overview
      8. Browsing the Visual Basic and .NET Documentation
      9. Quick Launch Tool
      10. Showing the Hierarchy of Method Calls
      11. Summary
    3. Chapter 3. The Anatomy of a Visual Basic Project
      1. Brief Overview of Types and Members
      2. Visual Basic 2012 Reserved Keywords
      3. Understanding Project Files
      4. Understanding References
      5. Summary
    4. Chapter 4. Data Types and Expressions
      1. Introducing the Common Type System
      2. Understanding Value Types
      3. Understanding Reference Types
      4. Differences Between Value Types and Reference Types
      5. Converting Between Value Types and Reference Types
      6. Understanding Conversion Operators
      7. Working with .NET Fundamental Types
      8. Common Operators
      9. Iterations, Loops, and Conditional Code Blocks
      10. Summary
    5. Chapter 5. Debugging Visual Basic 2012 Applications
      1. Preparing an Example
      2. Debugging Instrumentation
      3. Inspecting Object Details with Debugger Visualizers
      4. Debugging in Code
      5. Summary
    6. Chapter 6. Handling Errors and Exceptions
      1. Introducing Exceptions
      2. Handling Exceptions
      3. Summary
  12. Part II: Object-Oriented Programming with Visual Basic 2012
    1. Chapter 7. Class Fundamentals
      1. Declaring Classes
      2. Fields
      3. Properties
      4. Types and Members Visibility: Scope
      5. Executing Actions with Methods
      6. Partial Classes
      7. Partial Methods
      8. Constructors
      9. Shared Members
      10. Common Language Specification
      11. Summary
    2. Chapter 8. Managing an Object’s Lifetime
      1. Understanding Memory Allocation
      2. Understanding Garbage Collection
      3. Understanding the Finalize Method
      4. Understanding Dispose and the IDisposable Interface
      5. Restoring Objects with Object Resurrection
      6. Advanced Garbage Collection
      7. Summary
    3. Chapter 9. Organizing Types Within Namespaces
      1. Understanding Namespaces
      2. Organizing Types Within Namespaces
      3. Global Namespaces and the Global Keyword
      4. Summary
    4. Chapter 10. Modules
      1. Modules Overview
      2. Differences Between Modules and Classes
      3. Summary
    5. Chapter 11. Structures and Enumerations
      1. Understanding Structures
      2. Assigning Structures to Variables
      3. Passing Structures to Methods
      4. Members’ Visibility
      5. Inheritance Limitations and Interface Implementation
      6. Memory Allocation
      7. Organizing Structures
      8. Overloading Operators
      9. Structures and Common Language Specification
      10. Enumerations
      11. Summary
    6. Chapter 12. Inheritance
      1. Applying Inheritance
      2. Illustrating System.Object in Detail
      3. Introducing Polymorphism
      4. Overriding Members
      5. Conditioning Inheritance
      6. Accessing Base Classes Members
      7. Constructors’ Inheritance
      8. Shadowing
      9. Overriding Shared Members
      10. Practical Inheritance: Building Custom Exceptions
      11. Summary
    7. Chapter 13. Interfaces
      1. Defining Interfaces
      2. Implementing and Accessing Interfaces
      3. Interfaces and Polymorphism
      4. Interfaces Inheritance
      5. Defining CLS-Compliant Interfaces
      6. Most Common .NET Interfaces
      7. Summary
    8. Chapter 14. Generics and Nullable Types
      1. Introducing Generics
      2. Creating and Consuming Generics
      3. Introducing Nullable Types
      4. Summary
    9. Chapter 15. Delegates and Events
      1. Understanding Delegates
      2. Handling Events
      3. Offering Events to the External World
      4. Summary
    10. Chapter 16. Working with Collections and Iterators
      1. Understanding Collections Architecture
      2. Working with Nongeneric Collections
      3. Working with Generic Collections
      4. Building Custom Collections
      5. Concurrent Collections
      6. Iterators in Visual Basic
      7. Summary
    11. Chapter 17. Creating Objects: Visual Tools and Portable Libraries
      1. Visual Studio Class Designer
      2. Class View Window
      3. Generate from Usage
      4. Creating Portable Classes
      5. Summary
  13. Part III: Advanced Language Features
    1. Chapter 18. Manipulating Files and Streams
      1. Manipulating Directories and Pathnames
      2. Handling Exceptions for Directories and Pathnames
      3. Manipulating Files
      4. Introducing Streams
      5. Summary
    2. Chapter 19. The My Namespace
      1. Introducing the My Namespace
      2. My.Application
      3. My.Computer
      4. My.Settings
      5. My.Resources
      6. My.User
      7. My.WebServices
      8. Extending My
      9. My in Different Applications
      10. Summary
    3. Chapter 20. Advanced Language Features
      1. Local Type Inference
      2. Array Literals
      3. Extension Methods
      4. Anonymous Types
      5. Relaxed Delegates
      6. Lambda Expressions
      7. Ternary If Operator
      8. Generic Variance
      9. Summary
  14. Part IV: Data Access with ADO.NET and LINQ
    1. Chapter 21. Introducing ADO.NET and DataSets
      1. System Requirements
      2. Introducing ADO.NET
      3. Introducing DataSets
      4. Summary
    2. Chapter 22. Introducing LINQ
      1. What Is LINQ?
      2. LINQ Examples
      3. Language Support
      4. Understanding Providers
      5. Overview of LINQ Architecture
      6. Summary
    3. Chapter 23. LINQ to Objects
      1. Introducing LINQ to Objects
      2. Querying in Memory Objects
      3. Introducing Standard Query Operators
      4. Summary
    4. Chapter 24. LINQ to SQL
      1. Introducing LINQ to SQL
      2. Querying Data with LINQ to SQL
      3. Insert/Update/Delete Operations with LINQ
      4. Advanced LINQ to SQL
      5. LINQ to SQL with SQL Server Compact Edition 3.5
      6. Summary
    5. Chapter 25. LINQ to DataSets
      1. Querying Datasets with LINQ
      2. LINQ to DataSets’ Extension Methods
      3. Summary
    6. Chapter 26. Introducing ADO.NET Entity Framework
      1. Introducing Entity Framework
      2. Understanding Entity Data Models
      3. Insert/Update/Delete Operations for Entities
      4. Querying EDMs with LINQ to Entities
      5. Querying EDMs with Entity SQL
      6. Mapping Stored Procedures
      7. Introducing the Code First Approach
      8. Compatibility with the Past and with Other Technologies
      9. Summary
    7. Chapter 27. Manipulating XML Documents with LINQ and XML Literals
      1. Introducing LINQ to XML
      2. Writing XML Markup in VB with XML Literals
      3. XML Schema Inference
      4. Summary
  15. Part V: Building Windows Desktop Applications
    1. Chapter 28. Creating WPF Applications
      1. What Is WPF?
      2. Introducing the WPF Architecture
      3. Building WPF Applications with Visual Studio 2012
      4. Understanding the eXtensible Application Markup Language
      5. Understanding Visual Tree and Logical Tree
      6. Handling Events in WPF
      7. Arranging Controls with Panels
      8. Managing Windows
      9. Introducing the Application Object
      10. Brief Overview of WPF Browser Applications
      11. Summary
    2. Chapter 29. WPF Common Controls
      1. Introducing WPF Controls Features
      2. Understanding the ContentControl
      3. Understanding Common Controls
      4. Frame
      5. Using Common Dialogs
      6. Summary
    3. Chapter 30. Brushes, Styles, Templates, and Animations in WPF
      1. Introducing Brushes
      2. Introducing Styles
      3. Introducing Control Templates
      4. Introducing Transformations
      5. Introducing Animations
      6. Summary
    4. Chapter 31. Manipulating Media and Documents
      1. Viewing Images
      2. Playing Media
      3. Manipulating Documents
      4. Viewing XPS Documents
      5. Summary
    5. Chapter 32. Introducing Data-Binding
      1. Introducing the Data-Binding in WPF
      2. Discussing the Drag’n’Drop Data-Binding
      3. Summary
    6. Chapter 33. Localizing Applications
      1. Introducing .NET Localization
      2. Windows Forms Localization
      3. WPF Localization
      4. Summary
  16. Part VI: Building Web Applications
    1. Chapter 34. Building ASP.NET Web Applications
      1. Introducing the ASP.NET Model
      2. Web Forms and Master Pages
      3. ASP.NET Controls
      4. Handling Events
      5. Understanding State Management
      6. Creating a Web Application with VB 2012 with Navigation and Data-Binding
      7. Configuring a Web Application for Security
      8. Summary
    2. Chapter 35. Publishing ASP.NET Web Applications
      1. Deployment Overview
      2. Classic Publishing
      3. MSDeploy Publish
      4. Summary
    3. Chapter 36. Building Rich Internet Applications with Silverlight 5
      1. Introducing Silverlight
      2. Creating Silverlight Projects with Visual Basic 2012
      3. Adding Controls and Handling Events
      4. Playing Media
      5. Animating UI Elements
      6. Introducing Navigation Applications
      7. Introducing WCF RIA Services
      8. “Out-of-Browser” Applications
      9. XAML Debugging
      10. Additional New Features in Silverlight 5
      11. Summary
    4. Chapter 37. Building and Deploying Applications for Windows Azure
      1. Overview of the Windows Azure Platform
      2. Registering for the Windows Azure Developer Portal
      3. Downloading and Installing Tools for Visual Studio
      4. Creating a Demo Project
      5. Deploying Applications to Windows Azure
      6. Summary
    5. Chapter 38. Building Apps for Windows Phone 7.5
      1. Introducing Windows Phone
      2. Developer Registration to the Windows Phone Marketplace
      3. Downloading the Developer Tools
      4. The Windows Phone 7.5 Programming Model
      5. Creating Apps with Visual Basic
      6. Setting Properties, Icons, and Splash Screen
      7. Submitting Apps to the Marketplace
      8. Summary
  17. Part VII: Networking and Exposing Data Through Networks
    1. Chapter 39. Creating and Consuming WCF Services
      1. Introducing Windows Communication Foundation
      2. Implementing WCF Services
      3. Consuming WCF Services
      4. Handling Exceptions in WCF
      5. Hosting WCF Services in Internet Information Services
      6. Configuring Services with the Configuration Editor
      7. Summary
    2. Chapter 40. Implementing and Consuming WCF Data Services
      1. What Are Data Services?
      2. Implementing WCF Data Services
      3. Consuming WCF Data Services
      4. Implementing Service Operations
      5. Implementing Query Interceptors
      6. Understanding Server-Driven Paging
      7. Summary
  18. Part VIII: Advanced .NET Framework with VB 2012
    1. Chapter 41. Serialization
      1. Objects Serialization
      2. XML Serialization
      3. Custom Serialization
      4. Serialization with XAML
      5. Serialization in Windows Communication Foundation
      6. Serialization in the ADO.NET Entity Framework
      7. Summary
    2. Chapter 42. Processes and Multithreading
      1. Managing Processes
      2. Introducing Multithreading
      3. Understanding the .NET Thread Pool
      4. Threads Synchronization
      5. Summary
    3. Chapter 43. Parallel Programming and Parallel LINQ
      1. Introducing Parallel Computing
      2. Understanding and Using Tasks
      3. Parallel Loops
      4. Debugging Tools for Parallel Tasks
      5. Concurrent Collections
      6. Introducing Parallel LINQ
      7. Summary
    4. Chapter 44. Asynchronous Programming
      1. Overview of Asynchrony
      2. Before .NET 4.5: Event-based Asynchrony
      3. Before .NET 4.5: The Asynchronous Programming Model
      4. .NET 4.5: Introducing the Async Pattern
      5. Getting Started with Async/Await
      6. Exception Handling in Async
      7. Implementing Task-based Asynchrony
      8. Cancellation and Progress
      9. Asynchronous Lambda Expressions
      10. Asynchronous I/O File Operations in .NET 4.5
      11. Summary
    5. Chapter 45. Working with Assemblies
      1. Assembly Overview
      2. Understanding Application Domains
      3. Security Model in .NET 4.5
      4. Summary
    6. Chapter 46. Reflection
      1. Introducing Reflection
      2. Understanding Assemblies’ Metadata
      3. Getting Assembly Information
      4. Reflecting Types
      5. Invoking Code Dynamically
      6. Generating Code at Runtime with Reflection.Emit
      7. Caller Information
      8. Summary
    7. Chapter 47. Coding Attributes
      1. Applying Attributes
      2. Coding Custom Attributes
      3. Reflecting Attributes
      4. Summary
    8. Chapter 48. Platform Invokes and Interoperability with the COM Architecture
      1. Importing and Using COM Objects
      2. Exposing .NET Objects to the COM World
      3. P/Invokes and Unmanaged Code
      4. References to the Win32 API Calls
      5. Summary
    9. Chapter 49. Documenting the Source Code with XML Comments
      1. Understanding XML Comments
      2. Implementing XML Comments
      3. Generating Compiled Help Files
      4. Summary
  19. Part IX: Applications Deployment
    1. Chapter 50. Understanding the Global Assembly Cache
      1. The Dll Hell Problem
      2. The Global Assembly Cache
      3. Summary
    2. Chapter 51. Setup and Deployment Projects with InstallShield for Visual Studio
      1. Windows Installer Overview
      2. Introducing InstallShield
      3. Creating a Setup Project
      4. Configuring the Setup Project
      5. Building and Deploying the Windows Installer Package
      6. Summary
    3. Chapter 52. Deploying Applications with ClickOnce
      1. Introducing ClickOnce
      2. Deploying Applications with ClickOnce
      3. Configuring ClickOnce
      4. Security Considerations
      5. Programmatically Accessing ClickOnce
      6. Registration-Free COM
      7. Summary
  20. Part X: Mastering the Visual Studio 2012 IDE
    1. Chapter 53. Advanced IDE Features
      1. Exporting Templates
      2. Customizing Visual Studio 2012
      3. Managing User Settings
      4. Customizing the Toolbox
      5. Using, Creating, and Managing Reusable Code Snippets
      6. Managing Libraries with NuGet
      7. Summary
    2. Chapter 54. Introducing Visual Studio Extensibility
      1. Introducing Visual Studio Extensibility
      2. Building a Visual Studio Package
      3. Deploying Visual Studio Extensions
      4. Managing Extensions with Extensions and Updates
      5. Managing Add-Ins with the Add-In Manager
      6. Extending the Code Editor
      7. Summary
    3. Chapter 55. Advanced Analysis Tools
      1. Introducing Analysis Tools
      2. Performing Code Analysis
      3. Calculating Code Metrics
      4. Code Clone Detection
      5. Profiling Applications
      6. Historical Debugging with IntelliTrace
      7. Generating Dependency Graphs
      8. Summary
    4. Chapter 56. Testing Code with Unit Tests, Test-Driven Development, and Code Contracts
      1. Testing Code with Unit Tests
      2. Introducing Test Driven Development
      3. Understanding Code Contracts
      4. Summary
  21. Appendix
    1. Appendix A. Useful Resources and Tools for Visual Basic 2012
      1. Visual Basic Resources in MSDN
      2. Useful Developer Tools for Visual Basic
  22. Index
  23. Ad Pages