Back to description
This is an exciting time to enter the world of programming with Visual Basic 2008 and Windows Vista. Windows Vista represents... more
This is an exciting time to enter the world of programming with Visual Basic 2008 and Windows Vista. Windows Vista represents the first Windows operating system upgrade since Windows XP was first released in 2002. A lot has changed in the Windows user interface and Visual Basic 2008 makes it easy to write professional-looking Windows applications as well as web applications and web services. Haven’t upgraded to Windows Vista yet? No worries, Visual Basic 2008 also allows you to write professional-looking applications for Windows XP as well.
The goal of this book is to help you use the Visual Basic 2008 programming language, even if you have never programmed before. You will start slowly and build on what you have learned in subsequent chapters. So take a deep breath, let it out slowly, and tell yourself you can do this. No sweat! No kidding!
Programming a computer is a lot like teaching a child to tie his shoes. Until you find the correct way of giving the instructions, not much is accomplished. Visual Basic 2008 is a language you can use to tell your computer how to do things. But, like a child, the computer will understand only if you explain things very clearly. If you have never programmed before, this sounds like an arduous task, and sometimes it can be. However, Visual Basic 2008 gives you an easy-to-use language to explain some complex tasks. Although it never hurts to have an understanding of what is happening at the lowest levels, Visual Basic 2008 frees the programmer from having to deal with the mundane complexities of writing Windows applications. You are free to concentrate on solving real problems.
Visual Basic 2008 helps you create solutions that run on the Microsoft Windows operating systems, such as Windows Vista, Windows Server 2008, and Windows Mobile 6. If you are looking at this book, you might have already felt the need or desire to create such programs. Even if you have never written a computer program before, as you progress through the Try It Out exercises in this book, you will become familiar with the various aspects of the Visual Basic 2008 language, as well as its foundations in the Microsoft .NET Framework. You will find that it is not nearly as difficult as you had imagined. Before you know it, you will feel quite comfortable creating a variety of different types of programs with Visual Basic 2008.
Visual Basic 2008 can also be used to create web applications and web services as well as mobile applications that can run on Pocket PCs or SmartPhones. However, you will begin by focusing on Windows applications before extending your boundaries to other platforms.
This chapter covers the following topics:
Event-driven programming
The installation of Visual Basic 2008
A tour of the Visual Basic 2008 Integrated Development Environment (IDE)
How to create a simple Windows program
How to use the integrated Help system
... less
The .NET Framework provides an unprecedented platform for building Windows, web, and mobile applications with one or more... more
The .NET Framework provides an unprecedented platform for building Windows, web, and mobile applications with one or more languages. It is a definitive guide, encompassing and encapsulating where we have come from as a development community and, of course, where we are going.
.NET has been a success in many respects. Within the .NET Framework, new languages (C# and J#) have been born, and the well-established Visual Basic language has been reborn. The .NET Framework even supports legacy languages such as C++.
The .NET Framework provides the base for all development using Visual Studio 2008. It provides base classes, available to all Visual Studio 2008 languages for such functions as accessing databases, parsing XML, displaying and processing Windows and Web forms, and providing security for your applications. All languages in Visual Studio 2008 share and use the same base classes, making your choice of a programming language in Visual Studio 2008 a matter of personal preference and syntax style.
In this chapter, you will examine the following topics:
What the .NET Framework is
The .NET vision
Why Microsoft dared to spend $2 billion on a single development project
Now that you have Visual Basic 2008 up and running and even written a simple program, you’re going to look at the fundamentals... more
Now that you have Visual Basic 2008 up and running and even written a simple program, you’re going to look at the fundamentals behind the process of writing software and start putting together some exciting programs of your own.
In this chapter, you will:
Learn about algorithms
Learn to use variables
Explore different data types, including integers, floating-point numbers, strings, and dates
Study scope
Learn about debugging applications
Learn more about how computers store data in memory
In Chapter 3, you learned about algorithms and their role in programming. In this chapter, you’re going to look at how you... more
In Chapter 3, you learned about algorithms and their role in programming. In this chapter, you’re going to look at how you can control the flow through your algorithms so that you can make decisions like, “If X is the case, go and do A; otherwise do B.” This ability to make decisions is known as branching. You’ll also see how you can repeat a section of code (a process known as looping) a specified number of times, or while a certain condition applies.
Specifically, you’ll learn more about:
The If statement
If
Select Case
For loops
Do loops
Do
In the previous chapters, you worked with simple data types, namely Integer and String variables. Although these data types... more
Integer
String
In the previous chapters, you worked with simple data types, namely Integer and String variables. Although these data types are useful in their own rights, more complex programs call for working with data structures; that is, groups of data elements that are organized in a single unit. In this chapter, you learn about the various data structures available in Visual Basic 2008. You also will see some ways in which you can work with complex sets of data. Finally, you learn how you can build powerful collection classes for working with, maintaining, and manipulating lists of complex data.
In this chapter, you learn about:
Arrays
Enumerations
Constants
Structures
In the past, user interface (UI) designers have often relied on tools like Adobe Dreamweaver and Photoshop to develop screen... more
In the past, user interface (UI) designers have often relied on tools like Adobe Dreamweaver and Photoshop to develop screen mockups of Windows applications and HTML for web applications. Although these tools do provide designers with cutting-edge tools to create graphics, they are limited to creating graphics and have limited ability to create actual Windows forms and web forms. Up to this point, these limited tools have hindered UI designers from creating rich user interfaces, forcing them to rely on developers who have access to tools like Visual Studio.
Microsoft has recognized the separation of duties between UI designers and developers and has created a new language and a new set of tools to assist UI designers, allowing them to create the Windows forms and web forms that will be used by developers to create world class applications.
This new language comes in the form of the Extensible Application Markup Language (XAML), pronounced Zammel. Because XAML is an extensible application markup language, the language defines the elements of the user interface. This allows not only Microsoft to create tools for designing user interfaces such as Expression Blend and Expression Design, but other companies as well. One such example of this is the Aurora XAML Designer from Mobiform Software, which enables UI designers to create user interfaces for Windows and web applications.
In this chapter, you will learn:
What XAML is and how it applies to the .NET Framework
How XAML relates to the Windows Presentation Foundation (WPF)
How to create WPF applications in Visual Studio 2008
When Microsoft first released Visual Basic 1.0, developers fell in love with it, because it made building the user interface... more
When Microsoft first released Visual Basic 1.0, developers fell in love with it, because it made building the user interface components of an application very simple. Instead of having to write thousands of lines of code to display windowsthe very staple of a Windows applicationdevelopers could simply “draw” the window on the screen.
In Visual Basic (any version), a window is known as a form. With the .NET Framework, this form design capability has been brought to all of the managed languages as Windows Forms in Windows Forms Applications and as Windows in WPF Applications. You’ve been using Windows Forms over the course of the previous chapters and in the last chapter you learned about Windows in WPF Applications. However, you haven’t really given that much thought to themfocusing instead on the code that you’ve written inside them.
In this chapter, you’ll look in detail at Windows Forms and Windows and learn how you can use Visual Basic 2008 to put together fully featured Windows applications using Windows Forms Application projects and WPF Application projects. In particular, you will look at:
Adding more features using buttons, text boxes, and radio buttons
Creating a simple toolbar and toolbar buttons to respond to events
Creating additional forms and windows in your applications
Visual Basic 2008 provides several built-in dialog boxes that help you provide a rich user interface in your front-end applications... more
Visual Basic 2008 provides several built-in dialog boxes that help you provide a rich user interface in your front-end applications. These dialog boxes provide the same common user interface that is found in most Windows applications. They also provide many properties and methods that allow you to customize these dialog boxes to suit your needs while still maintaining the standard look of Windows Forms applications.
In this chapter, you will learn about the following:
Creating a message box using different buttons and icons
Creating an Open dialog box that enables you to open files
Creating a Save dialog box that enables you to save files
Creating a Font dialog box that enables you to apply the selected font to text
Creating a Color dialog box that enables you to define and select custom colors
Creating a Print dialog box that prints text from your application
Creating a Browse dialog box that enables you to browse for folders
This chapter explores these dialog boxes in depth and shows how you can use them in your Visual Basic 2008 applications to help you build more professional-looking applications for your users.
Menus are a part of every good application and provide not only an easy way to navigate within an application but also useful... more
Menus are a part of every good application and provide not only an easy way to navigate within an application but also useful tools for working with that application. Take, for example, Visual Studio 2008. It provides menus for navigating the various windows that it displays and useful tools for making the job of development easier through menus and context menus (also called pop-up menus) for cutting, copying, and pasting code. It also provides menu items for searching through code.
This chapter takes a look at creating menus in your Visual Basic 2008 applications. You explore how to create and manage menus and submenus and how to create context menus and override the default context menus. Visual Studio 2008 provides two menu controls in the Toolbox, and you explore both of these.
Create menus
Create submenus
Create context menus
Debugging is an essential part of any development project, as it helps you find errors in your code and in your logic. Visual... more
Debugging is an essential part of any development project, as it helps you find errors in your code and in your logic. Visual Studio 2008 has a sophisticated debugger built right into the development environment. This debugger is the same for all languages that Visual Studio 2008 supports. When you have mastered debugging in one language, you can debug in any language that you can write in Visual Studio 2008.
No matter how good your code is, there are always going to be some unexpected circumstances that will cause your code to fail. If you do not anticipate and handle errors, your users will see a default error message about an unhandled exception, which is provided by the common language run-time package. This is not a user-friendly message and usually does not clearly inform the user about what is going on or how to correct it.
This is where error handling comes in. Visual Studio 2008 also provides common structured error-handling functions that are used across all languages. These functions allow you to test a block of code and catch any errors that may occur. If an error does occur, you can display your own user-friendly message that informs the user of what happened and how to correct it, or you can simply handle the error and continue processing.
This chapter looks at some of the debugging features available in Visual Studio 2008 and provides a walk-through of debugging a program. You examine how to set breakpoints in your code to stop execution at any given point, how to watch the value of a variable change, and how to control the number of times a loop can execute before stopping. All of these can help you determine just what is going on inside your code. Finally, this chapter takes a look at the structured error-handling functions provided by Visual Studio 2008.
Examine the major types of errors that you may encounter and how to correct them
Examine and walk through debugging a program
Examine and implement error handling in a program
You may have heard the term object oriented a lot since you first started using computers. You may also have heard that it... more
You may have heard the term object oriented a lot since you first started using computers. You may also have heard that it is a scary and tricky subject to understand. In its early years it was, but today’s modern tools and languages make object orientation (OO) a wonderfully easy-to-understand concept that brings massive benefits to software developers. This is mainly because languages such as Visual Basic, C++, and, of course, Visual Basic 2008 and C# have matured to a point where they make creating objects and the software that uses them very easy indeed. With these development tools, you will have no problem understanding even the most advanced object-oriented concepts and will be able to use them to build exciting object-based applications.
You have been using objects and classes throughout this book, but in this chapter you look at object orientation in detail and build on the foundations of the previous chapters to start producing some cool applications using Visual Basic 2008.
Build a reusable object with methods and properties
Inherit the object that you build in another object
Override methods and properties in your base object
Create your own namespace
In Chapter 11, you looked at how you can build your own objects. Prior to that, you had been mostly using objects that already... more
In Chapter 11, you looked at how you can build your own objects. Prior to that, you had been mostly using objects that already existed in the .NET Framework to build your applications. In this chapter, you’ll take a look at some more object-oriented software development techniques.
In the first half of this chapter, you create your own classes. You will create a single-tier application like the others we have discussed so far in this book. The idea of creating two-tier applications, as opposed to single-tier applications, will be introduced in Chapter 14. You then learn about creating your own shared properties and methods. These are very useful when you want a method or property to apply to a class as a whole rather than a specific instance of that class. Finally, you look at memory management in Visual Studio 2008 and what you can do to clean up your objects properly.
Create classes that can be used by multiple applications
Learn about shared properties and methods
Learn about memory management in the .NET Framework
In this chapter, you’re going to look at building libraries of classes, a process that gathers many of the concepts covered... more
In this chapter, you’re going to look at building libraries of classes, a process that gathers many of the concepts covered in this book, so let’s have a quick review. So far, you’ve learned a lot about developing Windows applications by dragging controls onto forms, editing their properties, and adding code. When you edit a form in the Form Designer, you are actually designing a new class that inherits from the System.Windows.Forms.Form class.
System.Windows.Forms.Form
When you make changes to the form in the designer, the designer works out what code needs to be added to the class. You can view this code by clicking the Show All Files icon in the Solution Explorer and then opening the designer-generated code for your form. When you run the program, an instance of this class is createdan object. Like most objects, the form has state and behavioryou can have variables and controls on the form (state) and you can perform actions when, for example, the user clicks a button on the form (behavior). In theory, you could write your forms without using the designer at all; very few programmers work this way while creating Windows forms.
Right from the start you’ve been creating classes. You’ve also looked at creating your own classes from scratch. Recall what you studied about building objects in Chapter 11, where you created a project called Objects, which contained the classes Car and SportsCar. These classes were used in a console application because it made the objects easier to test, but they would have worked just as well in a Windows application. You could even have used them in a web application or web service. In fact, one of the key benefits of using classes is that once you’ve designed a good one, you can use it over and over again in different applications.
Car
SportsCar
Create your own class libraries and learn how to get information about existing libraries that are not part of the .NET Framework.
Learn to assign strong-name assemblies (compiled files) to ensure that all assemblies have a unique identity.
Register assemblies in a repository called the Global Assembly Cache (GAC) so that they can be shared between applications on the same computer.
In this book, you have used many of the controls that come with the .NET Framework, from the Button and the TextBox controls... more
In this book, you have used many of the controls that come with the .NET Framework, from the Button and the TextBox controls to the ListBox control. You may even have tried to use some of the more advanced controls such as the DataGrid and the TreeView controls. Although at first some of them may be hard to use, they offer a lot of functionality. These controls make it easy to create a user interface in your applications. Once you get to know how to use all their features, you will find that creating user interfaces also becomes a faster experience. Another important aspect that makes controls so useful is that they are reusable. You can drag and drop a Button control onto any form in any new Windows project and it works as a button should. The reuse factor is an important reason why Visual Basic, in general, became one of the most popular and is one of the most powerful development languages in use today. Did you know that you owe much of what you experience today in Visual Studio 2008, like Windows Forms Controls, to Visual Basic? The history of Windows Forms Controls has roots in something known as controls Visual Basic Extension (VBX). This later became more widely known as ActiveX, and today, revitalized and reborn into the .NET Framework, it is known as Windows Forms Controls.
Learn what a Windows Forms Control is and how it works
Create and use a Windows Forms Control
Learn to add methods and events to your control
Learn to code for design time and run time
NOTE
These controls are best suited for Windows Forms rather than web applications. To learn about Web Forms User Controls you should turn to Chapter 20. This chapter concentrates on the Windows Forms version.
Additionally, you will need Microsoft Visual Basic 2008 Professional Edition or above in order to complete the Try It Out exercises in this chapter.
So far, you have built user interfaces entirely from existing controls or controls that you created based on other controls... more
So far, you have built user interfaces entirely from existing controls or controls that you created based on other controls. When you are writing programs with Visual Basic 2008, you also have the freedom to draw your own user interface. This gives you absolute freedom over the look and feel of your programs, and makes certain programming tasks possible.
In this chapter, you look at the graphics and drawing functionality available in Visual Basic 2008. You will be introduced to the concepts by building a fairly complex drawing program, just to illustrate how simple drawing your own user interface actually is. Toward the end of the chapter, you will examine some of the multimedia features of Visual Basic 2008 and learn how you can display common Internet file formats such as .gif, .jpg, and .png.
.gif
.jpg
.png
Learn about the System.Drawing namespace
System.Drawing
Use pens and brushes
Learn how to select and use colors
Size and stretch images
Create your own Paint program
Most applications manipulate data in some way. Visual Basic 2008 applications often manipulate data that come from relational... more
Most applications manipulate data in some way. Visual Basic 2008 applications often manipulate data that come from relational databases. To do this, your application needs to interface with relational database software such as Microsoft Access, Microsoft SQL Server, Oracle, or Sybase.
Visual Studio 2008 provides the data access tools and wizards to connect to these databases and retrieve and update their data. In this chapter, you will look at some of these tools and wizards and use them to retrieve data from a database.
In Chapter 17, you will concentrate more on writing code directly, which gives you more flexibility and control than relying on Visual Studio 2008 to create it for you. With practice, writing code will also take less time than working through a wizard.
Learn what a database really is
Examine the SQL SELECT statement
SELECT
Examine data access components
Examine data binding in Windows Forms
Use the data access wizards in Visual Studio 2008
Note
Note that in order to work through the exercises in this chapter, you will need Microsoft Access 2000 or higher.
Chapter 16 introduced database programming. You obtained data from a single table in an Access database and displayed it... more
Chapter 16 introduced database programming. You obtained data from a single table in an Access database and displayed it on a grid. You managed to give the user some cool features while writing virtually no code.
You used wizards that wrote most of the code for youincluding setting up the connection, configuring the data adapter, and generating a typed dataset. This works great for simple database access using one or two tables, but writing the code yourself can give you a lot more control.
This chapter dives much deeper into the topic of database access. The database access technologies you used in the previous chapter, including components for retrieving data, storing data in memory, and binding data to controls, are collectively called ADO.NET. You will explore how you can use the built-in capabilities of ADO.NET to retrieve and update data from databases. You will also learn to manipulate, filter, and edit data held in memory by the DataSet.
DataSet
The data you extract will be bound to controls on your form, so you will also need to explore binding more thoroughly. You will see how you can use controls to view one record at a time (for example, using text boxes) and how to navigate between records, using the CurrencyManager object.
CurrencyManager
Learn about ADO.NET objects
Bind data to controls
Search for and sort in-memory data using ADO.NET DataView objects
DataView
Select, insert, update, and delete data in a database using ADO.NET
Learn how to use Language-Integrated Query (LINQ) to write VB code and select data from different data sources and update a database
You will also learn how to access SQL Server databases using the SqlClient data provider. As mentioned in the previous chapter, SqlClient is significantly faster than OleDb, but it works only with SQL Server databases. To complete the exercises in this chapter, you need to have access to a version of MSDE, SQL Server 2000, or SQL Server 2005, as well as full access to the Pubs database. If you do not have a copy of the Pubs database, you can lookup where to find the Pubs database for your version on your favorite search engine. Also, you may use the links in the list that follows to find a script to create the database. When this chapter uses the term SQL Server, the term includes SQL Server 2000, as well as MSDE and SQL Server 2005. The database can reside in SQL Server on your local machine or in SQL Server on a network.
SqlClient
OleDb
Need help locating a copy of the SQL Server? You can download SQL Server 2005 Express for free. The version used for this chapter is SQL Server Express with Advanced Services. You can get it from www.microsoft.com/sql and choose editions from the menu. The direct url is http://msdn2.microsoft.com/en-us/express/bb410792.aspx. This site also has links for downloading sample 2005 databases (not Pubs) and Books Online (SQL Help files).
www.microsoft.com/
http://msdn2.microsoft.com/en-us/express/bb410792.aspx
Need help locating a copy of the Pubs database? Go to the following resources:
SQL Server 2000 scripts and instructions can be downloaded from www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en. This script will work with 2005 versions. This is the easiest place to get the database.
www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en
If the links are hard to type, just go to www.microsoft.com/downloads and search for SQL Server Sample Databases. The search results will contain the preceding link.
www.microsoft.com/downloads
The msi package you download and install will install to C:\SQL Server 2000 Sample Databases (drive may change based on your configuration). You can then open the file instpubs.sql into SQL Management Studio and execute the code and the puds database will be created and loaded with data.
C:\SQL Server 2000 Sample Databases
instpubs.sql
Here are some notes for installing SQL 2005 Express with Advanced Services:
On the Feature Selection Screen, be sure to install all of the Client Components. This installs Microsoft SQL Server Management Studio Express, which is a terrific tool for writing SQL and managing your databases outside of Visual Studio.
For Chapter 17, you may install a named instance of WROX to avoid having to customize the code.
Chapter 17 uses mixed mode authentication to allow a username and password to be passed into SQL Server. The chapter uses the sa login with a password of wrox, which has system admin rights. This is not normally how you would login your application to SQL Server. For production, create a login that has a few rights as possible to use or use windows authentication where you can give rights to users or groups.
As we look to the future, the Internet is sure to increase its presence in business. Developers need to gain knowledge of... more
As we look to the future, the Internet is sure to increase its presence in business. Developers need to gain knowledge of building robust, dynamic web sites. In this chapter, you will learn about building Web Forms applications. You will focus on the basics for web site development and move to database-driven applications. With Visual Studio 2008, you will be building data-driven sites in no time.
Visual Studio 2008 is the best tool for created ASP.NET sites on the market today. The tool provides you with the best Intellisense, debugging, and control library to create web sites written in Visual Basic. You can build ASP.NET web sites (sometimes referred to as Web Form Applications), web services and even sites targeted for mobile devices in VS 2008. Also, you do not need IIS or any web server to host your site with VS 2008; ASP.NET Development Server is a built-in web server you can use to host your sites while developing them.
Look at a basic overview of web applications (thin-client applications)
See the advantages of Web Forms versus Windows Forms
Understand the control toolbox
Explore client and server processing
Assess the possible locations for web sites in VS 2008 (IIS and ASP.NET Development Server)
Error handling has been omitted from all of the Try It Outs in this chapter to save space. You should always add the appropriate error handling to your code. Review Chapter 10 for error-handling techniques.
Before you get your first look at the code, you will have a short lesson on the building blocks developers use to create web applications.
In Chapter 18, you learned how to implement many pieces of the puzzle that is web development. Now, you put it all together... more
In Chapter 18, you learned how to implement many pieces of the puzzle that is web development. Now, you put it all together to build the foundation for a secure public web site. You create a skeleton web site in this chapter, with security that is ready for content. Although you won't be writing any Visual Basic code, you end up with a consistent look and feel and role-based forms authentication. You will be amazed at the ease of creation and the flexibility built into ASP.NET.
Have an overview of the two most popular methods of web site security
Learn about the Web Site Administration Tool
Implement web site security using forms authentication
Add rules and roles to a security scheme
Create a secure web site with little or no code written
Error handling has been omitted from all of the Try It Outs in this chapter to save space. You should always add the appropriate error handling to your code. Review Chapter 9 for error-handling techniques.
Put simply, Extensible Markup Language (XML) is used for exchanging data between applications. Although it has been around... more
Put simply, Extensible Markup Language (XML) is used for exchanging data between applications. Although it has been around for some time, XML has established itself as the de facto data exchange standard for Internet applications. Today, XML is used not only on the Internet but to exchange data between many different platforms and applications.
In this chapter, you are not going to get bogged down in the details regarding XML such as its validation and well-formedness. Instead, you get a general introduction to XML, and then you look at its role with Visual Basic 2008. After that, you focus on using XML inside an application.
In this chapter, you:
Gain a deeper understanding of XML and what it looks like
Learn how to read and write XML files
Learn how to serialize and deserialize XML data
Learn how to navigate through an XML document
Learn how to change existing XML data and add new data to an XML document
With the release of the .NET Framework 3.0, came Windows Communication Foundation (WCF). WCF was the integration of distributed... more
With the release of the .NET Framework 3.0, came Windows Communication Foundation (WCF). WCF was the integration of distributed technologies like web services, MSMQ, and NET Remoting into the same framework. The WCF creates a baseline so all of your distributing programming is similar. Now, developers can use all of these technologies without having to completely learn each of them as new. This chapter focuses on web services and at the end look at securing your web service using Web Services Enhancements 3.0(WSE).
Get an overview of SOAP, the method used to exchange data with web services
Build a web service
Get an overview of WCF
Learn how to build WCF services and learn how to consume them
According to Wikipedia (http://en.wikipedia.org/wiki/Workflow): “A workflow is a reliably repeatable pattern of activity... more
http://en.wikipedia.org/wiki/Workflow
According to Wikipedia (http://en.wikipedia.org/wiki/Workflow): “A workflow is a reliably repeatable pattern of activity enabled by a systematic organization of resources, defined roles and mass, energy and information flows, into a work process that can be documented and learned. Workflows are always designed to achieve processing intents of some sort, such as physical transformation, service provision, or information processing.” That sounds like workflow is pretty important stuff. In today’s business world you will hear the term workflow over and over again.
As you build programs, you will need to integrate some type of workflow support. For example, when a new customer signs up for an account you may want the program to handle some type of workflow. In Windows Workflow Foundation (WF), there are two basic types of workflows: sequential workflows (also referred to as system) and state machine workflows (also known as human/event-driven). A sequential workflow is designed in a manner where one process happens after another until the workflow is complete. A state machine workflow is designed to handle external events; it does not typically have a set start and end. Take a look at two scenarios, each involving processes used by a cell phone.
Here’s a breakdown of some of the phone events and states of a cell phone:
Letter key pressed
Function key pressed
Phone call received
Text message received
Battery critically low
No service found
Dialing
Call in progress
First, consider a process that would be a good candidate for a state machine workflow: entering a series of key presses into your cell phone. If you have a phone that can text message and e-mail, the phone probably goes through many decisions as you start pressing the keys.
As you press keys, the phone responds to the events. Imagine you have a smartphone with a qwerty keypad and the number pad is mixed into the keys, so when you type DE it could also be 52. The phone will make decisions as you type. If the phone finds a match in your address book for Dennis Smith, it might display that as a choice along with Dennis’ phone number. As you keep typing, you move off of the number pad by typing DENNI and now the phone selects Dennis Smith for you and gives you a menu of items. Would you like to call, email, or text? Then, as an incoming call interrupts the flow, the screen goes blank, and the phone rings. You answer the phone. In this case, the workflow to place a call was stopped by the incoming call. A process that can be interrupted by an external event is not a good choice for a sequential workflow, so this process calls for a state machine workflow.
Now consider a scenario that’s a better candidate for implementing a sequential workflow: using speed dial. To make a call using speed dial, you hold down the 1 key for several seconds. Once the key press has lasted two seconds, the speed dial sequential flow is started. The process flow and decisions might look like these for a complete speed dial call:
1. Number 1 key pressed and held for two seconds.
2. Start speed dial process.
3. Does phone have service?
4. If yes, set phone in dialing state (this locks phone from external interruptions).
5. Retrieve number stored for speed dial key pressed.
6. Dial number.
7. Connect call.
Why is this a good candidate for a sequential workflow? First, the process does not accept interruptions from external sources. Therefore, this process must complete once started. A speed dial call will always start when a key is held for two seconds, even if an incoming call attempts to come through. This means that a speed dial call has a defined start and end. These two items make it a good candidate for a sequential workflow.
In these simple examples, the two workflows are very similar. As you design and lay out the events, processes, and states of an application, you should be able to see if it is a good candidate for a sequential or state machine workflow. Remember the rules:
When you have a workflow that has a well-defined start and end and that does not have to respond to external events, you should choose a sequential workflow implementation.
When the steps of a workflow can happen in any order and external applications can change the state of the workflow then use a state machine workflow.
In this chapter, you will work with sequential workflows.
WF includes a graphical designer that enables you to lay out the workflow visually. The designer allows you to lay out your code as in a Visio program. When you are satisfied with the layout, you can then place the logic into the code pages to finish the workflow. It is a very intuitive design and easy to use.
One of the key pieces to WF is the built-in ability to create long-running transactions. You can create workflows that wait for decisions from people and systems, taking into account possible waits from systems being down or message delivery that is delayed. WF also includes the capability to roll back these long-running workflows if errors occur. In this chapter, you will:
Look at a basic overview of sequential workflows
Review the different workflow project types
Take a look at workflow activities
Create sequential workflows
Now, let’s take a look at some pieces, start putting them together, and build a couple of workflows.
Error handling has been omitted from all of the Try It Out exercises in this chapter to save space. You should always add the appropriate error handling to your code. Review Chapter 10 for error-handling techniques.
Mobile devicesmore specifically, personal digital assistants (PDAs)are being shipped to more and more people around the... more
Mobile devicesmore specifically, personal digital assistants (PDAs)are being shipped to more and more people around the world. A market once owned by Palm’s Operating System is now a market full of devices running Microsoft Windows CE. According to a report published November 12, 2004, by the Associated Press, Windows CE first took the top place over Palm in number of PDAs shipped in the third quarter 2004. Of the 2.8 million PDAs shipped worldwide, Windows CE was the operating system on 48.1 percent. According to a summary of the Gartner PDA Report for Q1 2006 (www.palminfocenter.com/news/8564/gartner-pda-report-for-q1-2006/), Windows Mobile OS is now running on over 50 percent of the PDA’s shipped. This represents over a.1.8 million devices shipped in that three-month period. The demand for applications to make PDAs and other smart devices valuable to companies is growing with the number of PDAs in use by corporations. As you build skills in Visual Studio 2008, know that building applications for smart devices is definitely a skill many employers are and will be looking for in their developers.
www.palminfocenter.com/news/8564/gartner-pda-report-for-q1-2006/
Designing mobile applications for Windows CE, Pocket PC, and Smartphone devices is simplified using Visual Studio 2008. This chapter focuses on applications built for PDAs running Microsoft Windows Mobile operating system.
In this chapter you learn:
The differences between the full .NET framework and the Compact Framework
How to use ActiveSync and Windows Mobile Device Center to connect to smart devices
How to create mobile applications
How to use the built-in emulator to test mobile applications
Deploying an application can be a complicated process, especially when dealing with large, complex applications. A wealth... more
Deploying an application can be a complicated process, especially when dealing with large, complex applications. A wealth of knowledge is required on nearly every aspect of a development. A large software installation for Windows requires you to have knowledge ranging from Registry settings, MIME types, and configuration files to database creation and manipulation. Companies tend to rely on dedicated deployment software for these large installations, together with key people who understand the processes involved. However, Visual Studio 2008 does provide some basic deployment functionality, which is tremendously helpful for the standard developer and smaller installations.
Under the Visual Studio 2008 banner, you can create many different types of applications, from desktop to web applications and services. All of these have varying degrees of complexity or peculiarities when it comes to installation time.
Since this is a beginner’s guide, this chapter will not go into depth on specifics regarding the deployment of the different applications; rather, it provides an overview of deployment.
Learn concepts and terminology
Deploy a ClickOnce Application with Visual Studio 2008
Create a setup program with Visual Studio 2008
Edit the installer user interface
Now that you have come to the end of this book, you should have a relatively good idea of how to write code using Visual... more
Now that you have come to the end of this book, you should have a relatively good idea of how to write code using Visual Basic 2008. The topics and example code covered in this book have been designed to provide you with a firm foundation, but it is just the beginning of your journey. In fact, this book is just one of the many steps you are going to take on your road to becoming a full-fledged Visual Basic 2008 programmer. Although you have come a long way, there is still a lot farther to go, and you will certainly have many more questions on the way.
The problem now is, where do you get these questions answered, and, of course, “What next?”
This appendix offers you some advice on what your possible next step(s) could be. As you can imagine, a number of different routes are open to any one person. The path you choose will probably depend on what your goal is or what you are being asked to do by your employer. Some of you will want to continue at a more general level with some knowledge about all aspects of Visual Basic 2008, while others may want to drill down into more specific areas.
Well, it is extremely important not to take a long break before carrying on with Visual Basic 2008. If you do so, you will find that you will quickly forget what you have learned. The trick is to practice. You can do this in a number of ways:
Continue with the examples from this book. Try to add more features and more code to extend the examples. Try to merge and blend different samples together.
You may have an idea for a new program. Go on and write it.
Try to get a firm understanding of the terminology.
Read as many articles as you can. Even if you do not understand them at first, bits and pieces will come together.
Make sure you communicate your knowledge. If you know other programmers, get talking and ask questions.
Consult our online and offline resources for more information.
The rest of this appendix lists available resources, both online and offline, to help you decide where to go next.
This appendix contains the solutions for the various chapter exercises found throughout the book.... more
This appendix contains the solutions for the various chapter exercises found throughout the book.
So here you are, ready to go out into the world and build applications with Visual Basic 2008. Congratulate yourself; you... more
So here you are, ready to go out into the world and build applications with Visual Basic 2008. Congratulate yourself; you should be excited at having worked your way through all the chapters of the book. Soon, creating applications will become second nature to you. As you work in IT, you will play many roles on teams. In some cases, your manager will only ask you to write code. The main portion of this book provides a strong understanding of what you will need to do in that situation. Other times, management will ask you to wear many hats on a project and be responsible for delivering an entire solution. This appendix introduces you to what it takes to create a successful solution.
Let’s start with a basic question. How is a solution different from an application? A solution is the entire process of creating a system for a customer. The solution includes planning, documenting, testing, releasing, training, and supporting the application. The application is just one part of the solution.
Microsoft has a set of processes and models that to some is the standard for solution delivery in the IT industry: Microsoft Solutions Framework (MSF). Software developers around the globe apply this framework to internal strategies to ensure best practices when building software. The MSF is a recent interpretation of the classic software development life cycle and provides guidance to project management. In this appendix, you will
Learn about the software development life cycle.
Get an overview of the MSF and how it relates to the software development life cycle.
See how to manage trade-offs.
Learn how to define success for a project.
A detailed explanation of the Framework would take two or three hundred pages. This appendix is just a concise summary. Keep this in mind as you begin to explore this tool. To get more info online, you can visit www.microsoft.com/technet/solutionaccelerators/msf/default.mspx.
www.microsoft.com/technet/solutionaccelerators/msf/default.mspx
In today’s electronic world, consumers are bombarded with scams via the Internet and e-mail. If you plan to write applications... more
In today’s electronic world, consumers are bombarded with scams via the Internet and e-mail. If you plan to write applications that take advantage of these technologies, you must be aware of fraudulent activity of others. The most rampant activity today is a tactic known as phishing. In this scam, a fraudulent e-mail or pop-up message lures a user to a fake web site on the pretext that a breach in bank security or unwanted account activity has made it necessary to “verify” the user’s account information. Tricked users will see a site that looks like their bank’s site but is actually being hosted by criminals in an attempt to bait users into entering their personal and financial information. In these schemes, it is easy for concerned customers to be tricked and enter their card number, social security number, or PIN into the web forms to avoid their accounts being frozen. Little do they know they are giving away their private information to thieves.
Phishing is not the only scam consumers must deal with, but it is one of the most prevalent. As a developer, it is your job to make applications safe. The use of certain features in your application can make it easier for criminals to impersonate. If your application avoids asking for personal information that you do not need over e-mail or the Web, users may be more alert to a scam when it occurs. You can never assume that e-mail will not be intercepted over the Internet. Make sure you never treat e-mail as a secure means of data transmission.
You must also be aware of security for your Windows applications and assemblies. It seems as though a new hole is found every week in some browser or operating system that allows a hacker to run code on a user’s machine. One way in which this type of attack is commonly accomplished is by a buffer overflow. To give you a simple explanation, hackers discover that a program has memory allocated to store data only up to a certain size. The attacker sends a larger object than the memory allocated. The extra data is not discarded, but rather it gets written to adjacent areas of memory that are intended to store code or the addresses of code. This may corrupt valid allocations of memory, but more important, it installs the attacker’s malicious code in memory. The victim program runs the attacker’s code as if it were its own, and the damage is done. The root cause of this problem is not one most Visual Basic developers will encounter, but it should make you aware that people may use your functions in ways you did not intend them to be used, including malicious ways.
Take a look at another example of a software bug that might be a security risk. Say you wrote an assembly or web service that would upload files to your company’s web site. This application is for salespeople to upload comma-separated files of current sales data each night. The code allows the path and file name to be passed as parameters, and it can be used by numerous departments because of this flexibility. The problem is that this same flexibility allows a hacker to upload a Web page, place it into the root web directory, and do almost anything to the server or network. You should change this web service to store files in a locked-down directory and modify the file name so that an attacker would not be able to access the file by name. Functions like this one are prevalent in many companies’ code libraries and create most of the security holes these companies will face.
In this appendix you will learn about security issues and how to handle them within the following topics:
Understanding code access security
Secure Sockets Layer (SSL)
Where to look for security answers
Microsoft has added a new feature to the .NET Framework 3.0: Windows CardSpace. (Formerly, this software was known as InfoCard... more
Microsoft has added a new feature to the .NET Framework 3.0: Windows CardSpace. (Formerly, this software was known as InfoCard.) This is a new type of identity management system that removes the old user name and password you are used to on the Web. The overall idea is that the users creates your cards and then you can choose which cards to assign to different sites. These cards can contain varying amounts of personal info, so for a very public site you can use a card that includes the minimum requirement for that site. For more personal information like a banking site, you can create a card with more data or even have a card issued to you from a bank that is a card provider. For some users, this will be a great solution.
In this appendix we discuss two new versions of the .NET Framework: versions 3.0 and 3.5. Visual Studio 2005 was based on... more
In this appendix we discuss two new versions of the .NET Framework: versions 3.0 and 3.5. Visual Studio 2005 was based on version 2.0 of the .NET Framework. Visual Studio 2008 is based on the .NET Framework 3.5. With the release of Vista, .NET Framework 3.0 was released. Version 3.0 included broad new features to support Vista and version 3.5 included smaller incremental changes.
Purchase Before purchasing this product, please be sure you have met all software and system requirements, and that you understand any limits placed upon its use.
Return Policy Wrox Chapters on Demand are non-returnable and non-refundable.
Reader Software Wrox Chapters on Demand are offered as PDFs, and they must be viewed using the Adobe Reader. If you do not have the Reader installed, it can be downloaded for free at Adobe.com.
Test Download As Wrox Chapters on Demand purchases are non-returnable, it is advisable that you test your system and software configurations with a free sample download before you place an order.
Usage Rights for a Wrox Chapter on Demand File Any Wrox Chapter on Demand product you purchase from this site will come with certain restrictions that allow Wiley to protect the copyrights of its products. After you purchase and download this title, you:
If you have any questions about these restrictions, you may contact Customer Care at (877) 762-2974 (8 a.m. - 5 p.m. EST, Monday - Friday). If you have any issues related to Technical Support, please contact us at 800-762-2974 (United States only) or 317-572-3994 (International) 8 a.m. - 8 p.m. EST, Monday - Friday).
Related Books
Visual Basic Resources