VISUAL BASIC .NET PROGRAMMING BLACK BOOK
Visual Basic 6 Black Book Author(s): Steven Holzner NET Black Book by Steven Holzner programming practices, from design tools to flowcharts. Contains. Visual cittadelmonte.info Black Book is a comprehensive reference and problem-solving guide for Visual Basic programmers. It covers Visual cittadelmonte.info tips. NET Black Book Edition is a comprehensive reference and best Visual Basic programming practices, from design tools to flowcharts.
|Language:||English, Spanish, Japanese|
|Genre:||Health & Fitness|
|ePub File Size:||18.73 MB|
|PDF File Size:||15.17 MB|
|Distribution:||Free* [*Regsitration Required]|
NET Black Book is a comprehensive reference and problem-solving guide for I would buy "Programming visual cittadelmonte.info (Core References) by Francesco. Visual Basic. NET Programming Black Book [Steven Holzner] on cittadelmonte.info * FREE* shipping on qualifying offers. Please Read Notes: Brand New. Visual Basic 6 Black Book Author(s): Steven Holzner. 1, Pages·· MB ·9, Downloads. Visual Basic Programming Conventions Code Commenting.
NET tips, examples, and how-tos on everything from programming to managing the development of Visual Basic applications, and provides in-depth material on the new object-oriented features of Visual Basic. BackCover Visual Basic. Upgrading from Visual Basic 6. The Visual Basic Language: Handling Exceptions Immediate Solutions: Beeping Chapter 5: Windows Forms:
To close the application, click the X button at upper right, as you would with any Windows application.
Running a Windows application. This is the magic of Visual Basicwith one line of code, we've created a functioning application. That's our first Visual Basic application, already up and running. Make sure you save the WinHello application Visual Basic will save all files when it runs an application, but you also can use the File Save All menu item before moving on.
If you look in the IDE's title bar and in the tabs above the code window in Figure 1. In fact, all this is pretty familiar to Visual Basic 6. This application will do the same as the Windows application we've just seen, but it'll run on a Web server and appear in a browser. Give this new application the name WebHello, as you see in Figure 1. You can enter the location of your server in the Location box in the New Projects dialog box; if you have IIS running on your local machine, Visual Basic will find it and use that server by default, as you see in Figure 1.
Designing a Web application. As you also can see in Figure 1. You can see a note in the Web form under designcalled a pageat the center of the IDE that says that we're using the Grid layout mode. In this mode, controls will stay where you position them, just as they did when we created our Windows application. The other layout mode is the Flow layout mode; in this mode, the controls in your application will move around, as they would in a standard Web page, depending on where the browser wants to put them.
Visual Basic .NET Black Book by Steven Holzner
If your Web application happens to start in Flow layout mode, click the Web form itself, then set the pageLayout property in the Pproperties window at lower right to GridLayoutif you've used Visual Basic before, you're already familiar with the properties window; it's also covered in detail later in this chapter.
Now we can design our new Web application just as we did the Windows applicationclick the Web forms item in the toolbox, and add both a text box and a button to the Web form, as you see in Figure 1. Adding controls to a Web application. And, as before, we can double-click the button to open its associated code, as you see in Figure 1.
Adding code to a Web application. We can add the same code to handle the button click as before; find this code in the code window: That's all it takesnow run the application by selecting the Debug Start menu item, or pressing F5.
The application comes up in your browser, as shown in Figure 1. Running a Web application. That's our first Web applicationto close the application, just close the browser window. As you can see, this Web application is remarkably similar to our Windows application, and that's the primary inspiration behind VB. Web applications such as this one use HTML to display their controls in a Web page, so there are more limitations on those controls than on Windows controls, but as you can see, the design process is very similar.
Behind the scenes, Visual Basic. NET has been storing the application's files on the Web server automaticallyno special uploading needed. Anyone with a browser can look at the application on the Internet, simply by navigating to its URL in this case, that's http: If you're like me, the first time you create and run a Web application, you'll feel a lot like saying Wow. Web applications like this will make Web development a great deal easier and more popular on IIS platforms.
NETconsole applications. These applications are command-line based and run in DOS windows. This gives one the feeling once again that VB. However, the change is a welcome one, because it provides us with an option for very simple programming, without worrying about user interface implementation and issues.
To see how console applications work, use the File New Project menu item to open the New Project menu item, and select Console Application in the Templates box, as shown in Figure 1. Name this new project ConsoleHello, as also shown in Figure 1. Then click OK to create the new project. Creating a Console application. When you create this new project, you see the result in Figure 1.
Coding a Console application. The code here looks like this: Console applications are based on Visual Basic modules that are specifically designed to hold code that is not attached to any form or other such class. Notice also the Sub Main procedure here. As we'll see in more depth in Chapter 3, a Sub procedure is a series of Visual Basic statements enclosed by the Sub and End Sub statements. When the console application is run, those statements are run automatically.
We can display our "Hello from Visual Basic" message in this console application using the WriteLine method, a prewritten procedure available to us in Visual Basic. This method is part of the System. Console class, which in turn is part of the System namespace.
The System. Console class is part of the. NET framework class library, along with thousands of other classes. To organize all those classes,. NET uses namespaces. This gives classes their own space and stops conflicts between the various names in such classes; for example, if two classes defined a WriteLine method, you could keep them from conflicting by placing them in different namespaces so Visual Basic knows which one you mean. We'll become more familiar with namespaces starting in Chapter 2; for now, we can use WriteLine to display our message, like this: Module Module1 Sub Main System.
You can run this program now by selecting the Debug Start menu item; when the program runs, it displays both our message and the prompt about the Enter key, like this: Hello from Visual Basic Press any key to continue. You can see this result in Figure 1. There, the DOS window stays open until the user is ready to dismiss it by pressing the Enter key, or by clicking the X button at upper right in the DOS window.
Running a Console application. Windows applications are already familiar to Visual Basic 6. In fact, there's a great deal that's new in VB. NET; I'll take a look at what's new in overview now. What's New in VB. Rather than asking what's new, it would almost be easier to ask what's not new in VB. The changes are extensive. We can't cover all the changes from Visual Basic 6. We'll note the details of these changes throughout the book.
Be warned: However, it might prove useful to at least simply skim this section, because besides giving you an outline of what's changed from VB6, it also gives you an outline of the kind of programming we'll see in this book, and what's possible. Version 4. NET is far bigger. Not only has how you design applications and what types of projects you can create changed, but the very syntax of the language has changed a great deal too. Some programmers have complained that Microsoft is trying to turn Visual Basic into Java; if you know Java, you'll see what that means throughout the book in dozens of places, as what was standard in Java has become standard in Visual Basic.
Now, however, Microsoft has changed all that, giving the Visual Basic language the same rigor as any other programming language. This change will take some time for many accomplished VB programmers to come to terms with; for example, everything in Visual Basic is object-oriented now, as it is in Java, and you must declare your variables, as you do in Java, and the built-in VB functionality is encapsulated in a namespace called System, as it is in Java, and so on.
As we've also seen, aside from Windows development, you can also create Web applications in VB. In fact, there's a third alternative nowin addition to Windows applications and Web applications, you can create console applications, as you can in Java. Console applications, as we'll see in this chapter, are command-line oriented applications that run in DOS windows. Those are the three application types with user interfaces: Windows applications, Web applications, and console applications.
There's also an additional new type of applicationone that doesn't have a built-in user interface: Web services. Web services are applications that run on Web servers and that communicate with other programs, and we'll see them later in this book.
One of the biggest changes in VB. NET is that now everything is object oriented. All items, even variables, are now objects, and we'll see what that means starting in Chapter 2. NET, including inheritance, overloading, and polymorphism. Like Java, VB. NET does not support multiple inheritance, but it does support interfaces.
We'll get a good look at the OOP issues like these in Chapters 11 and You can also create multithreaded applications in VB. A threaded application can do a number of different things at the same time, running different execution threads. These threads can communicate with each other, pass data back and forth, and so on. This means, for example, that when your program is doing something heavily computation-intensive, your program's user interface, running in a different thread, can still respond to the user.
One of the biggest hurdles that VB6 programmers will have to overcome is the great change in Visual Basic syntax. Not only has the fundamental structure of Visual Basic projects like Windows applications become different, but there are a thousand other issues as wellfor example, you now have to declare all variables and objects, you must always use parentheses when calling procedures, many keywords are either gone or.
All this takes a great deal of effort to get used to, but VB. NET itself will usually tell you what you're doing wrong, and often will explain how to make it right. In fact, the very data types you can use have changed in VB. The reason for this, as we'll see in this chapter, is that the. NET framework that underlies VB. As you can see, there are plenty of changes in VB. I'll list them in overview in more detail here, starting with Web Development Changes.
Changes in Web Development The big change in Web development is that you can do it at all. As you can see, however, Web development is now an integral part of VB. The two major types of Web applications are Web forms and Web services, and we'll cover them both in this book.
Here's an overview: Web forms let you create Web-based applications with user interfaces. These applications are based on ASP.
You can view these applications in any browserthe application will tailor itself to the browser's capabilities. Server controls are displayed using HTML, but execute code on the server. Web services are made up of code that can be called by other components on the Internet or applications that use Internet protocols.
Web services may be used, for example, as the middle tier of distributed database applications on the Internet. You can also now check the data a user enters into a Web form using validation controls, which you can add to a Web form while designing it. You can bind the controls on a Web form to all kinds of different data sources, simply by dragging those sources onto Web forms and setting a few properties. There are two ways to create your own Web server controls: NET Framework.
Things have changed again; now you handle data with ADO. NET is a new data-handling model that makes it easy to handle data on the Internet. It's also what VB. NET uses on your local machine to communicate with local databases. At the heart of ADO.
For example, you no longer use record sets, but rather datasets. A dataset is a collection of one or more tables or record sets as well as the relationships between those tables or. Instead, ADO. Here is an overview of what's new in data handling: Data is handled through ADO. NET, which facilitates development of Web applications. NET is built on a disconnected data model that uses snapshots of data that are isolated from the data source. This means you can use and create disconnected, local datasets.
Datasets are based on XML schema, so they can be strongly typed. There are many new tools and a wizard for handling data in VB. NET, including tools to generate datasets from data connections. You can use the connection wizard or the server explorer to drag and drop whole tables from data sources, as well as creating data adapters, connection objects, and more.
You can now bind any control property to data from a data source. You can use the data classes provided in the. NET Framework to create and manipulate datasets in code. Changes in the Visual Basic Language As mentioned earlier, there are many changes to the Visual Basic language itself. You can now create multithreaded applications, and make use of structured exception handling, custom attributes, and more. Probably the biggest single change is that everything is object oriented now.
Generally speaking, a language is object oriented if it supports the following more on this in Chapters 11 and AbstractionThe ability to create an abstract representation of a concept in code as an object named employee is an abstraction of a real employee.
EncapsulationThis has to do with the separation between implementation and interface; that is, when you encapsulate an object, you make its code internal and not accessible to the outside except through a well-defined interface. PolymorphismBroadly speaking, this is the ability to create procedures that can operate on objects of different types. Visual Basic handles polymorphism with late binding and multiple interfaces, both of which we'll cover in this book.
InheritanceInheritance is the process by which you can derive new classes from other classes. Chapter 12 is all about inheritance in Visual Basic; the idea here is that if you were to create, for example, a class for a specific Visual Basic form and then derive a new type of form from that class, the derived class will inherit all the base's class's functionality, even before you start to customize the derived class by adding new functionality.
NET now uses namespaces to prevent naming conflicts by organizing classes, interfaces, and methods into hierarchies,. You can import various namespaces to gain access to its classes, interfaces, and methods, and we'll see more on this later in this chapter.
For example, the Microsoft. The Microsoft. The biggest namespace comes from the. NET framework itself, and is called System. For example, the class that supports Windows forms is System. The data types you can use are now restricted to those in the Microsoft Common Language Specification CLS as we'll see in the next chapter. On the one hand, that restricts what you can use for data types in Visual Basic, but on the other hand, it also means that any language that is CLS-compliant can use the classes, objects, and components you create in Visual Basic.
And you can use classes, components, and objects from other CLS-compliant programming languages. Many new concepts have been added to Visual Basic programming as well, such as assemblies, namespaces, delegates, and attributes, as we'll see in this chapter and in Chapter 2.
Here's an overview of some of the changes to the languagethere are too many to list them all here, but we'll see them throughout the book, especially in Chapters 11 and 12, where we cover OOP in VB. NET in depth: It's all OOP now. All data items are objects now, based on the System. Object class.
Even integers and other primitive data types are based on this class. And all code has to be enclosed in a class. You can now create classes that serve as the base class for derived classes. As mentioned above, this is called inheritance. Derived classes inherit, and can extend, the properties and methods of the base class. You can now overload properties, methods, and procedures.
Overloading means you can define properties, methods, or procedures that have the same name but use different data types. For example, overloaded procedures allow you to provide as many implementations as necessary to handle different kinds of data while giving the appearance of a single procedure. NET now supports multithreaded applications. NET now supports constructors and destructors for use when initializing an object of a specific class.
There are three new data types in VB. The Char data type is an unsigned bit type used to store Unicode characters. The Short data type is a signed bit integer named Integer in earlier Visual Basic versions. Finally, the Decimal data type is a bit signed integer only available as Variants in earlier versions of Visual Basic. The Variant type no longer exists; instead, the Object type is the catch-all type. Also, the Currency data type has been replaced by the Decimal type.
NET is now strongly typed; this means you must declare all variables by default, and you can't usually assign one data type to another.
You use the CType statement to convert between types. There are also changes in the way you declare variables. Arrays can no longer be 1-based in VB. That is, the Option Base statement no longer exists. User-defined types are no longer defined with the Type keyword, but rather with the Structure keyword.
In Visual Basic 6. NET, they come from the. Collections namespace, so we have to use the ones available in that namespace instead.
These operators combine two operations in one, as in Java. IfThen statements are now short-circuited, as in Java, so Visual Basic will evaluate only the operands it needs to determine the result of the statement see Chapter 2 for more information. You no longer need to use the Set statement to assign objects to variables.
The syntax for use with procedures has changedfor example, you now always need to use parentheses to enclose the arguments you're passing to a procedure. There are other changes as well; for example, optional parameters now require default values. In VB6 most parameters were passed by reference; in Visual Basic. NET, the default is passing by value. More on this in Chapter 3. The syntax for writing property procedures has changed including the fact that Get and Let have become Get and Set.
Structured exception handling, including TryCatchFinally blocks, is now supported. In VB. NET, however, default properties are no longer supported. Event-handling procedures have changed; now event handlers are passed only two parameters.
The Gosub keyword has been removed. The DefType keyword has been removed. Many functions, keywords, and collections from VB6 are now obsolete. Here's a partial list, along with replacements: Collection has been replaced by System.
The way programs handle COM components has also changed. That's all changed now, and some people think that VB. Although VB. COM components can be treated as. NET components by. NET components, because the. NET wrapper that. NET components. As you can see, there are a great many changes going on in VB.
Microsoft is aware that the sheer magnitude of all these differences can present a serious obstacle to the adoption of VB. NET as they say in the documentation, "Visual Basic. NET represents a major departure from previous versions of Visual Basic in several ways.
This Wizard is automatically invoked when you try to open a VB6 project, and you can see it in Figure 1. The Visual Basic Upgrade Wizard. NET projects, but in all but the simplest cases, I've found it inadequate, because the differences are too great. When you do upgrade a VB6 project of any complexity, you'll usually find the resulting code filled with Visual Basic commentslines of text that begin with an apostrophe ' to indicate to Visual Basic that they contain comments intended to be read by a person, not code to execute like this: Graphics statements can't be migrated.
In the majority of cases, the differences between VB6 and VB. NET are simply too many for the Upgrade Wizard to overcome. However, give it a try if you'd like; it can convert some of your application's code and perhaps save you a little time. Tip If you're truly stuck, you might try importing the Microsoft.
VB6 namespace we'll see how importing works in Chapter 2 into your application, which gives you access to obsolete VB6 keywords like Open, Close, CreateObject, and so on.
Unfortunately, for any but the simplest project, I suggest recoding by hand. It can be a tedious process, but there's no alternative. We've completed an overview of the differences between Visual Basic 6. NET, and now it's time to get cracking with VB.
NET itself. The first aspect to examine is the. NET part of VB. NET, and I'll do that now. NET is only one component of a revolution in Windows-the.
NET framework. This framework provides the new support for software development and operating system support in Windows, and it's more extensive than anything we've seen in Windows before. NET framework wraps the operating system with its own code, and your VB. NET programs actually deal with. NET code instead of dealing with the operating system itself.
And it is specially designed to make working with the Internet easy. At the base of the.
Visual Basic 6 Black Book Author(s): Steven Holzner - PDF Drive
NET applications. When you create a VB. When you run the application, that IL code is translated into the binary code your computer can understand by some special compilers built into the CLR. Compilers translate your code into something that your machine's hardware, or other software, can deal with directly.
NET applications, compiled into IL, will run on them. NET Framework class library is the second major part of the. The class library gives your program the support it needs-for example, your program may create several forms, and as there is a class for forms in the class library, your program doesn't have to perform all the details of creating those forms from scratch.
All your code has to do is declare a new form, and the CLR compilers can get the actual code that supports forms from the. NET Framework class library. In this way, your programs can be very small compared to earlier Windows applications; because you can rely on the millions of lines of code already written in the class library, not everything has to be in your application's executable EXE file. All this assumes that you're working on a machine that has the. NET Framework class library, installed.
The code for all elements we use in a VB. NET application-forms, buttons, menus, and all the rest-all comes from the class library. And other Visual Studio applications use the same class library, making it easy to mix languages in your programming, even in the same application.
Also, distributing applications is easier, because all the support you need is already on the machine you're installing your application to. As mentioned, the. NET framework organizes its classes into namespaces.
For example, the. NET framework includes the namespaces Microsoft. VisualBasic, Microsoft. JScript, Microsoft. CSharp, and Microsoft. In fact, these namespaces contain relatively few classes; the real way we'll interact with the. NET framework class library in this book is through the System namespace. NET application without using classes from the. NET System namespace, as we'll see over and over again in this book. When you want to use a Windows form, for example, you must use the System.
Form class. A button in a Windows form comes from the System. Button class, and so on. There are many such classes, organized into various namespaces like System. Here's an overview of some of those namespaces: System-Includes essential classes and base classes that define commonlyused data types, events and event handlers, interfaces, attributes, exceptions, and so on. Collections-Includes interfaces and classes that define various collections of objects, including such collections as lists, queues, arrays, hash tables, and dictionaries.
Data-Includes classes that make up ADO. NET lets you build data-handling components that manage data from multiple distributed data sources. NET data provider. Diagnostics-Includes classes that allow you to debug your application and to step through your code.
Also includes code to start system processes, read and write to event logs, and monitor system performance. Drawing2D-Includes classes that support advanced two-dimensional and vector graphics. Printing-Includes classes that allow you to customize and perform printing. The classes in this namespace allow users to create and use collections of fonts.
IO-Includes types that support synchronous and asynchronous reading from and writing to both data streams and files. Net-Provides an interface to many of the protocols used on the Internet. Sockets-Includes classes that support the Windows Sockets interface. If you've worked with the Winsock API, you should be able to develop applications using the Socket class.
Reflection-Includes classes and interfaces that return information about types, methods, and fields, and also have the ability to dynamically create and invoke types. Security-Includes classes that support the structure of the common language runtime security system. Threading-Includes classes and interfaces that enable multithreaded programming.
Services-Includes classes that let you build and use Web services, programmable entities. Forms-Includes classes for creating Windows-based forms that make use of the user interface controls and other features available in the Windows operating system.
Xml-Includes classes that support processing of XML. These, along with the many other System classes, form the foundation on which VB. NET applications rest. It's time now to start taking a look at how to build those applications. Building VB. NET, we have to get some terminology under our belts, because the. NET framework requires a new structure for applications. In particular, assemblies are now the building blocks of the. NET Framework; they form the fundamental unit of deployment, version control, reuse, security permissions, and more.
Assemblies You combine assemblies to form. NET applications, and although we won't deal with them directly very often, we need to get the terminology down. An assembly holds the Intermediate Language modules for your application.
When you create an application in VB. NET and run it, VB. That is, assemblies are how your applications interact with the. Here's what's in a. NET assembly: The manifest also lists the other assemblies needed to support this one, and explains how to handle security issues.
The actual meat of the assembly is made up of modules, which are internal files of IL code, ready to run. That's how VB. NET stores the IL it creates, in modules inside assemblies. Each module, in turn, contains types-the classes and interfaces that your code has defined, and that the assembly has to know about to let the various modules interact with each other.
We won't deal with assemblies directly much, because all that's needed happens behind the scenes with the CLR and the. NET framework-but we do have to know the terminology, because you'll hear these terms frequently when using VB. For example, to set the version of a Visual Basic project, you edit its AssemblyInfo.
Solutions and Projects When you created applications in Visual Basic 6. Each project held the code and data for an application, ActiveX control, or whatever else you wanted to build. If you wanted to combine projects together, you created a project group. NET, however, project groups have become far more integral to the development process, and now they're called solutions.
By default, when you create a new project in VB. NET, Visual Basic will create a new solution first, and then add a project to that solution. For example, look at the Solution Explorer window, at right in Figure 1. In that case, we've created our Visual Basic project called WinHello, and you can see that project in the Solutions Explorer-but note that Visual Basic has also placed that project inside a solution with the same name, WinHello.
If we were to add new projects to the current solution which you can do with the New Project dialog box , those new projects would appear in the Solution Explorer as part of the current solution. This is a change from VB6, where you created projects by default, not project groups. It's also worth noting that Microsoft calls the files in each project, such as the files for a form, items. So the terminology here is that solutions contain projects, and these in turn contain items.
File Extensions Used in VB. NET When you save a solution, it's given the file extension. Here's a list of the types of file extensions you'll see in files in VB. NET, and the kinds of files they correspond to; the most popular file extension is. This is a useful list, because if VB. NET has added files to your solution that you haven't expected, you often can figure them out by their file extension: NET application-level events.
Debug and Release Versions Note that so far we've started our programs from the Debug menu's Start item. This causes Visual Basic to launch the program while staying in the background; if there's a problem, Visual Basic will reappear to let you debug the program's code.
That's useful for development, of course, but when your program is ready to go and to be used by others, you hardly want them to have to launch your program from Visual Basic.
That's where the difference between debug and release versions of your program comes in. In a debug version of your program, Visual Basic stores a great deal of data needed to interface with the debugger in your program when it runs, and this not only makes the corresponding assembly larger, but also slower. In the release version of your program, the program doesn't have all that added data, and can run as a stand-alone.
NET Framework, of course. When you create a new solution, Visual Basic creates it in debug mode, meaning that you launch it from the Debug menu as we've been doing. However, you can switch to release mode in several ways like many things in VB. NET, there's more than one way to do it: Select the solution you want to set the mode for by clicking it in the Solution Explorer, and find its Active Config property in the properties window. When you click the right-hand column in the properties window next to this property, a drop-down list box will appear; select Release in that list box.
Select the solution you want to set the mode for by clicking it in the Solution Explorer, and select the Properties item in the Project menu, opening the solution's property pages. Select the Configuration Properties folder in the box at left, and the Configuration item in that folder. Then select Release from the drop-down list box in the configuration column of the table that appears, and click OK.
Probably the easiest way to set the solution mode to release or debug is simply to use the drop-down list box that appears in the Visual Basic. When you create a new solution or project, this list box displays the word Debug, and all you need to do to switch to release mode is to select Release instead. When you've set the mode for a solution to Release, you build it using the Build menu's Build item the Build menu item causes Visual Basic to compile only items it thinks have been newly changed; to force it to compile all items in the solution, choose the Rebuild All item instead of Build.
This builds the solution in a way that others can use it, and you can deploy your program this way usually with the help of a deployment project that you build in Visual Basic, as we'll do later in the book. Now we have the background we need on VB. NET solutions and projects as we head into the following chapters, where we'll assume this knowledge and put it to work.
We'll also take for granted that you know your way around Visual Basic. Part of the reasons it's become more complex is that the same IDE is now shared by all Visual Studio languages, such as VB and C something Microsoft has promised for many years, but only implemented now.
We've already seen the IDE at work, of course, but now it's time to take a more systematic look. There are so many independent windows in the IDE that it's easy to misplace or rearrange them inadvertently. The IDE windows are docking windows, which means you can use the mouse to move windows around as you like; when the windows are near an edge, they'll "dock"-adhere-to that edge, so you can reconfigure the IDE windows as you like.
If you move IDE windows inadvertently, don't panic; just use the mouse to move them back. Tip You also can restore the default window layout by selecting the Tools Options item, then selecting the General item in the Environment folder, and clicking the Reset Window Layout button.
That's really good to know, because sooner or later, Visual Basic will dock some window you didn't want to dock, such as the Edit Replace window, to the IDE, rearranging all your other windows, and it can take a long time to try to fix that manually. Also note that the windows in the IDE come with an X button at upper left, which means you can close them. I don't know about you, but I sometimes click these when I don't mean to, and a window I wanted disappears.
It's easy to panic: The toolbox is gone! I'll have to reinstall everything! In fact, all you have to do is to find that window in the View menu again such as View Toolbox to make it reappear. Note that some windows are hidden in the View Other Windows menu item, which opens a submenu of additional windows-there are simply too many windows to fit them all into one menu without needing to use a submenu. There's so much packed into the IDE that Microsoft has started to make windows share space, and you can keep them separate using tabs such as those you can see above the form at the center of Figure 1.
If you click the Form1. NET feature-are sharing the same space, and you can select between them using tabs. NET adds a new button in dockable IDE windows-a little thumbtack button at upper right as you see in various windows in Figure 1. This is the "auto-hide" feature, which lets you reduce a window to a tab connected to the edge it's docked on. For example, in Figure 1. If I let the mouse move over that tab, the full Sever Explorer window will glide open, covering most of the toolbox.
You can autohide most windows like this; for example, if I were to click the thumbtack button in the toolbox, it would close and become a tab under the Server Explorer tab in the IDE. To restore a window to stay-open status, just click the thumbtack again. And, of course, you can customize the IDE as well.
For example, to customize IDE options such as the fonts and colors used to display code, you select the Tools Options menu item and use the various items in the Environment folder. To customize menus and toolbars, such as specifying the toolbars to display How many are there to choose from? That's it for general discussion-it's time to get to the IDE itself, starting with the Start page.
The Start Page We've already seen the Start page, which is what you see when you first start Visual Basic, and which appears outlined in Figure 1. You can use the Start page to select from recent projects; by default, the Get Started item is selected in the Start page at upper left. You can also create a new project here by clicking the New Project button.
The Start page has other useful aspects as well: To make it search only pertinent help files, you can select the My Profile item in the Start page, and select either Visual Basic or Visual Basic and Related which is my preference in the Help Filter drop-down list box. Tip The Start page is actually being displayed in a browser. Its URL is vs: And if you have an URL in your code a quoted string that begins with "http: NET will turn that text into a hyperlink, underline it, and allow you to click that URL to bring up the corresponding Web page in place of the Start page.
The Menu System After you've started Visual Basic and have seen the Start page, you often turn to the menu system to proceed, as when you want to create a new project and use the File New Project menu item to bring up the New Project dialog box you can do the same thing by clicking the New Project button in the Start page.
The IDE menu system is very involved, with many items to choose from-and you don't even see it all at once. The menu system changes as you make selections in the rest of the IDE-for example, the Project menu will display 16 items if you first select a project in the Solution Explorer, but only 4 items if you have selected a solution, not a project.
In fact, there are even more dramatic changes; for example, try clicking a form under design and you'll see a Data menu in the menu bar, used to generate datasets.
If you then select not the form but the form's code, however for example, double-click the form to open the code window , the Data menu disappears. There are hundreds of menu items here, and many useful ones that will quickly become favorites, such as File New Project that you use to create a new project, or the most recently used MRU list of files and projects that you can access from the Recent Files or Recent Projects items near the bottom of the File menu. Tip You can set the number of items that appear in MRU lists by selecting the Tools Options menu item, clicking the Environment folder and selecting the General item, and entering a value in the "most recently used lists" text box.
The menu system also allows you to switch from debug to release modes if you use the Build Configuration Manager item, lets you configure the IDE with the Tools Options and Tools Customize items, and so on.
I'll introduce more and more menu items throughout the book as appropriate. Toolbars The toolbars feature is another handy aspect of the IDE. These appear near the top of the IDE, as shown in Figure 1.
There are plenty of toolbars to choose from, and sometimes VB. NET will choose for you, as when it displays the Debug toolbar when you've launched a program with the Start item in the Debug menu.
Visual Basic IDE toolbars. Because the IDE displays tool tips those small yellow windows with explanatory text that appear when you let the mouse rest over controls such as buttons in a toolbar , it's easy to get to know what the buttons in the toolbars do.
As mentioned, you can also customize the toolbars in the IDE, selecting which toolbars to display or customizing which buttons appear in which toolbars with the Tools Customize menu item, or you can rightclick a toolbar itself to get a menu of the possible toolbars to display the bottom item in this popup menu is Customize, which lets you customize which buttons go where , or you can open the Toolbars submenu in the View menu to do the same thing as is often the case in VB, there's more than one way to do it.
Toolbars provide a quick way to select menu items, and although I personally usually stick to using the menu system, there's no doubt that toolbar buttons can be quicker; for example, to save the file you're currently working on, you only need to click the diskette button in the standard toolbar as you see in Figure 1.
We've already used this quite a bit, and you can see it in Figure 1. The New Project dialog box. In addition to letting you select from all the possible types of projects you can create in Visual Basic, you can.
Note also that you can add projects to the current solution using the New Project dialog box; just click the Add to Solution radio button instead of the Close Solution one the default. If your project is entirely new, VB. NET will create an enclosing solution for the new project if there isn't already one. Finally, note the Setup and Deployment Projects folder, which you use to create projects for deploying your program as we'll do near the end of the book.
Graphical Designers When you're working on a project that has user interface elements-such as forms, VB. NET can display what those elements will look like at run time, and, of course, that's what makes Visual Basic visual. For example, when you're looking at a Windows form, you're actually looking at a Windows form designer, as you see in Figure 1. A Visual Basic application graphical designer. There are several different types of graphical designers, including: Windows form designers Web form designers Component designers XML designers You may have noticed-or may already know from VB6-that Windows forms display a grid of dots, which you can see in Figure 1.
To set the grid spacing, and specify whether or not controls should "snap" to the grid that is, position their corners on grid points , you can use the Tools Options menu item to open the Options dialog box, and select the Windows Form Designer folder, displaying the possible options for you to set. Code Designers Unlike graphical designers, code designers let you edit the code for a component, and you can see a code designer in Figure 1.
You can use the tabs at the top center of the IDE to switch between graphical designers such as the tabs Form1. You can also switch between graphical and code designers using the Designer and Code items in the View menu, or you can use the top two buttons at left in the Solution Explorer. A code designer. Note the two drop-down list boxes at the top of the code designer; the one on the left lets you select what object's code you're working with, and the one on the right lets you select the part of the code that you want to work on, letting you select between the declarations area, functions, Sub procedures, and methods all of which we'll see starting in Chapter 2.
The declarations area, which you select by selecting the Declarations item in the right-hand list box, is where you can put declarations of module-level objects, as we'll discover in Chapter 3 see "Understanding Scope" in that chapter.
Tip When you double-click a control in a graphical designer, its code designer will open and Visual Basic creates an event handler see "Handling Events" in Chapter 4 for its default event such as the Click event for buttons , which is a procedure that is called when the event occurs, as we'll see in Chapter 4. To add code to a different event handler, select the object you want to work with in the left-hand drop-down list box in the code designer, and select the event you want to add code to in the righthand drop-down list box; Visual Basic will create an event handler for that event.
Those are new in VB. NET, and were introduced because VB. NET now writes a great deal of code for your forms and components automatically. For example, here's what that code looks like for a typical Windows form: New 'This call is required by the Windows Form Designer. InitializeComponent 'Add any initialization after the InitializeComponent call End Sub 'Form overrides dispose to clean up the component list. Container 'NOTE: TextBox Me.
Button Me. SuspendLayout ' 'TextBox1 ' Me. Point 32, Me. Size , 20 Me. Point , 56 Me. Size 5, 13 Me. Size , Me. AddRange New System. Button1, Me. The IDE is cluttered enough, and this helps a little in uncluttering it. Tip You can use the Region and End Region directives in your own code as well, allowing you to expand and contract whole sections of code at once. As with the rest of the IDE, there are features upon features packed into code designers-for example, rightclicking a symbol lets you go to its definition, or its declaration, and so on.
IntelliSense One useful feature of VB. IntelliSense is what's responsible for those boxes that open as you write your code, listing all the possible options and even completing your typing for you. IntelliSense is one of the first things you encounter when you use VB. NET, and you can see an example in Figure 1. Using IntelliSense. Tip If you enter some code that VB.
NET considers a syntax error, it will underline the error with a wavy red line. You can rest the mouse over the underlined text to see a tool tip explaining what VB. NET thinks is wrong.
That's not part of the IntelliSense package, although it also is useful. IntelliSense is made up of a number of options, including: List Members-Lists the members of an object. Parameter Info-Lists the arguments of procedure calls.
Quick Info-Displays information in tool tips as the mouse rests on elements in your code. Complete Word-Completes typed words. Automatic Brace Matching-Adds parentheses or braces as needed.
There's also a Visual Basic-specific IntelliSense, which offers syntax tips that display the syntax of the statement you're typing. That's great if you know what statement you want to use but don't recall its exact syntax, because its syntax is automatically displayed. Tip IntelliSense is particularly useful when you can't remember what arguments a built-in Visual Basic procedure accepts if these terms are not familiar to you, note that they're coming up in the next chapter , because it'll display those arguments as you type in the call to the procedure.
Such procedures also can be overloaded, which means they have several forms that take different arguments-in such cases, IntelliSense will display an up and down arrow in its tool tip with the text "1 of n" where n is the number of overloaded forms, and you can use the arrows to select the overloaded form of the procedure you want prompts for.
IntelliSense is something you quickly get used to, and come to rely on. However, you can turn various parts of IntelliSense off if you want; just select the Tools Options menu item, then select the Text Editor folder, then the Basic subfolder, and finally the General item in the Basic subfolder.
You'll see a number of IntelliSense options you can turn on and off with check boxes.
The Object Explorer IntelliSense is useful because it tells you what syntax is correct automatically, or lists all the members of an object that are available. Another useful tool that's too often overlooked by Visual Basic programmers is the Object Explorer.
This tool lets you look at all the members of an object at once, which is invaluable to pry into the heart of objects you've added to your code. The Object Explorer helps open up any mysterious objects that Visual Basic has added to your code so you can see what's going on inside.
The Object Explorer shows all the objects in your program and gives you access to what's going on in all of them. To close the Object Explorer, just click the X button at its upper right.
The Toolbox The toolbox is something that all veteran Visual Basic developers are familiar with, and you can see it in Figure 1. The Visual Basic toolbox. Microsoft has crammed more into the toolbox with each successive version of Visual Basic, and now the toolbox uses tabs to divide its contents into categories; you can see these tabs, marked Data, Components, Windows Forms, and General, in Figure 1. The tabs available, as you might surmise, depend on the type of project you're working on-and even what type of designer you're working with.
The Data, Components, Windows Forms, and General tabs appear when you're working with a Windows form in a Windows form designer, but when you switch to a code designer in the same project, all you'll see are General and Clipboard Ring which displays recent items stored in the clipboard, and allows you to select from among them in the toolbox.
The Data tab displays tools for creating datasets and making data connections, the Windows Forms tab displays tools for adding controls to Windows forms, the Web Forms tab displays tools for adding server controls to Web forms, and so on. The General tab is empty by default, and is a place to store general components, controls, and fragments of code in. To see what your friends thought of this book, please sign up. To ask other readers questions about Visual Basic. Net Black Book , please sign up.
Be the first to ask a question about Visual Basic. Net Black Book. Lists with This Book. This book is not yet featured on Listopia. Community Reviews. Showing Rating details. More filters. Sort order. Jan 30, Minhajur Rahman Khan rated it liked it. Basic Programming in Visual Basic. View 1 comment. Mar 25, Eric Lyng rated it it was amazing. After 15 years, this book is still one of my most useful VB. A very well written book for beginners also.
I have trained several developers with this book. Although it is a good read for a programmer, it is more of a reference manual to help you get through troubleshooting of a vb. Jul 18, Abhishek Vachharajani marked it as to-read. Abed rated it it was amazing Oct 18, Naura rated it it was ok Apr 23, Vamsi Rathnakar rated it it was amazing Dec 21, Syedfarooq10 rated it it was amazing Dec 18, Balasubramanian rated it it was ok Feb 03, Vrinda Modi rated it really liked it Jan 06, Afeefa T rated it it was ok Dec 03, Feb 16, Neeta rated it really liked it.
Ahmad rated it it was amazing Jan 18, Ken Poirier rated it liked it Oct 19, Amine rated it liked it Dec 04, Srishti Gulati rated it it was amazing Sep 16, Prashant Pk rated it it was amazing Dec 30, Branden Beachy rated it it was amazing Feb 14, John rated it really liked it Dec 19, Balakrishna rated it liked it Oct 18, Shree rated it it was amazing Oct 15, Rajat Kumar rated it really liked it Jul 21, Afin rated it liked it Jan 16, Louie Agustin rated it liked it Feb 28, Mar 06, Anurag Kaushik added it.
This review has been hidden because it contains spoilers. To view it, click here. Diney Angel rated it did not like it Jan 17, Farzana Nishe rated it it was ok Oct 30, Prachi Ashok rated it it was amazing Aug 06, Urvi Mistry rated it it was amazing Apr 08, Eswari is currently reading it Mar 17, Vishnu Kumar added it Feb 18, Belete marked it as to-read Feb 22, Tapan added it Jul 22, Nakul Ambhore is currently reading it Jul 25, Subhrajit Das added it Jul 31, Kamrul is currently reading it Aug 26, Prabhu Wwe added it Sep 17, Waqar Shahid marked it as to-read Oct 18, Prabha Bhagat marked it as to-read Oct 21,