Introduction to Visual Basic

Visual Basic

Microsoft Visual Basic, the latest and greatest incarnation of the old BASIC language, gives you a complete Windows application development system in one package. Visual Basic (or VB, as we often call it) lets you write, edit, and test Windows applications. In addition, VB includes tools you can use to write and compile help files, ActiveX controls, and even Internet applications.
Visual Basic is itself a Windows application. You load and execute the VB system just as you do other Windows programs. You will use this running VB program to create other programs. VB is just a tool, albeit an extremely powerful tool, that programmers (people who write programs) use to write, test, and run Windows applications.
Although programmers often use the terms program and application interchangeably, the term application seems to fit the best when you're describing a Windows program because a Windows program typically consists of several files. These files work together in the form of a project. The project generates the final program that the user loads and runs from Windows by double-clicking an icon or by starting the application with the Windows Start menu.
The role of programming tools has evolved over the past 45 years along with computer hardware. A programming language today, such as Visual Basic, differs greatly from programming languages of just a few years ago. The visual nature of the Windows operating system requires more advanced tools than were available a few years ago. Before windowed environments, a programming language was a simple text-based tool with which you wrote programs. Today you need much more than just a language; you need a graphical development tool that can work inside the Windows system and create applications that take advantage of all the graphical, multimedia, online, and multiprocessed activities that Windows offers. Visual Basic is such a tool. More than a language, Visual Basic lets you generate applications that interact with every aspect of today's Windows operating systems.
If you've taken a look at Visual Basic in the past, you'll be amazed at today's Visual Basic system. VB now sports a true compiler that creates standalone runtime .EXE files that execute more quickly than previous VB programs. VB also includes several wizards that offer step-by-step dialog box questions that guide you through the creation of applications. VB's development platform, a development environment called the Developer Studio, now supports the same features as the advanced Visual C++ and Visual J++ compilers. Therefore, once you learn one of Microsoft's Visual programming products, you will have the skills to use the other language products without a long learning curve ahead of you.

Languages

Programming languages today are not what they used to be. The language itself has not gotten less important; rather, the graphical interfaces to applications have gotten more important.
A computer cannot understand any person's spoken language. A spoken language, such as Italian or English, is simply too general and ambiguous for computers to understand. Therefore, we must adapt to the machine and learn a language that the computer can understand. VB's programming language is fairly simple and uses common English words and phrases for the most part. The language is not ambiguous, however. When you write a statement in the Visual Basic language, the statement never has multiple meanings within the same context.
You will use the VB programming language to embed instructions within applications you create. All the code you write (code is the program's instructions) must work together to instruct the computer. Code is the glue that ties all the graphics, text, and processes together within an application. Code tells a checkbook application, for example, how to be a checkbook application and not something else. The program code lets the application know what to do given a wide variety of possible outcomes and user actions.

Visual Basics Three Editions

Visual Basic comes in three flavors: the Standard Edition, the Professional Edition, and the Enterprise Edition. Although we primarily use the Professional Edition, the Standard Edition is called the learning edition and provides the least expensive approach to using Visual Basic. The Standard Edition gives you a complete development environment, programming language, and many of the same tools the other editions offer. If you use the Standard Edition, you have a powerful programming tool. Some people develop only with the Standard Edition and never need anything else.
The Professional Edition offers a few more tools, including extra ActiveX add-in tools, better Internet programming support, a help file compiler, and improved database access tools. Most professional programmers use the Professional Edition.
The Enterprise Edition provides the client/server programmer with extended tools for remote computing and application distribution. Microsoft enhanced VB's performance for Enterprise Edition users working in a networked, distributed environment.
If you want to create your own ActiveX controls, you will need the VB Custom Control Edition that comes with the Professional and Enterprise Editions.

The VB Programming Process

When you want to use Visual Basic, you'll follow these basic steps:
1. Start Visual Basic.
2. Create a new application or load an existing application. When you create a new application, you might want to use Visual Basic's VB Application Wizard to write your program's initial shell, as you'll do in the next hour.
3. Test your application with the debugging tools Visual Basic supplies. The debugging tools help you locate and eliminate program errors (called bugs) that can appear despite your best efforts to keep them out.
4. Compile your program into a final application.
5. Quit Visual Basic.
6. Distribute the application to your users.
Rarely will you perform all these steps sequentially in one sitting. The six steps are not sequential steps, but stages that you go through and return to before completing your application.
Starting Visual Basic
You start Visual Basic from the Windows Start menu. The Visual Basic development environment itself usually appears on a submenu called Microsoft Visual Basic, although yours might be called something different due to installation differences. You will see additional programs listed on the Microsoft Visual Basic submenu, but when you select Visual Basic from the submenu, Visual Basic loads and appears on your screen.

Stopping Visual Basic

You'll exit from Visual Basic and return to Windows the same way you exit most Windows applications: Select File|Exit, click Visual Basic's main window close button, press Alt+F4, or double-click VB's Control menu icon that appears in the upper-left corner of the screen.
If you have made changes to one or more files within the currently open project (remember that a project is the collection of files that comprise your application), Visual Basic gives you one last chance to save your work before quitting to Windows.
Mastering the Development Environment
Learning the ins and outs of the development environment before you learn Visual Basic is somewhat like learning the parts of an automobile before you learn to drive; you might have a tendency to skip the terms and jump into the foray. If, however, you take the time to learn some of the development environment's more fundamental principles, you will be better able to learn Visual Basic. You then will be more comfortable within VB's environment and will have a better understanding of the related words when subsequent lessons refer to the windows and tools in the development environment.

Standards:
The Menu Bar and Toolbar
Visual Basic's menu bar and toolbars work just as you expect them to. You can click or press a menu bar option's hotkey (for example, Alt+F displays the File menu) to see a pull-down list of menu options that provides either commands, another level of menus, or dialog boxes. Many of the menu options have shortcut keys (often called accelerator keys) such as Ctrl+S for the File|Save option. When you press an accelerator key, you don't first have to display the menu to access the option.
The toolbar provides one-button access to many common menu commands. Instead of selecting Edit|Paste, for example, you could click the Paste toolbar button. As with most of today's Windows applications, Visual Basic supports a wide range of toolbars. Select View|Toolbars to see a list of available toolbars. Each one that is currently showing will appear with a checkmark by its name.
The Form Window: Where It All Happens
The Form window is your primary work area. Although the Form window first appears small relative to the rest of your screen, the Form window comprises the background of your application. In other words, if you write a Windows-based calculator with Visual Basic, the calculator's buttons all reside on the Form window and when someone runs the calculator, the calculator that appears is really just the application's Form window with components placed there and tied together with code.
Source program is code, forms, menus, graphics, and help files that you create and edit to form the project (also called source code).
The parts of the application that you create, such as the forms, the code, and the graphics that you prepare for output, comprise the source program. When you or another user compiles or runs the source program, VB translates the program into an executable program. You cannot make changes directly to an executable program. If you see bugs when you run the program, you must change the source application (which might contain multiple files in the project) and rerun or recompile the source.
The Toolbox Supplies Controls
The toolbox contains the controls that you place on the Form window. The toolbox never runs out of controls; if you place a command button on the Form window, another awaits you on the toolbox, ready to be placed also.
The Form Layout Window Places Forms
The Form Layout window displays the initial position and relative size of the current form shown in the Form window. The Form Layout window always shows where the form appears in the current Form window. If you want the form to appear at a different location from the current position, you can move the form inside the Form Layout window to move the form's appearing position when the user runs the application.
The Project Explorer Window
The Project Explorer window, often called the Project window, gives you a tree-structured view of all the files in the application. Microsoft changed the formal name from Project window to Project Explorer window between versions 4 and 5 to celebrate the resemblance of the window to the typical Explorer-like tree-structured file views so prevalent in Windows 95 and NT. You can expand and collapse branches of the view to get more or less detail.
The Project Explorer window displays forms, modules (files that hold supporting code for the application), classes (advanced modules), and more. When you want to work with a particular part of the loaded application, double-click the component in the Project window to bring that component into focus. In other words, if the Project Explorer window displays three forms and you need to edit one of the forms, locate and double-click the form name in the Project window to activate that form in the Form window.
The Properties Window
A different list appears in the Properties window every time you click over a different Form window tool. The Properties window describes properties (descriptive and functional information) about the form and its controls. Many properties exist for almost every object in Visual Basic. The Properties window lists all the properties of the Form window's selected control.
Help Is at Your Fingertips
Visual Basic's online help system is one of the most advanced on the market. When you want help with a control, window, tool, or command, press F1. Visual Basic analyzes what you are doing and offers help. In addition, Visual Basic supports a tremendous help resource called Books Online. When you select Books Online from the Help menu, Visual Basic displays a tree-structured view of books about Visual Basic that you can search and read. The online help extends to the Internet as well. If you have an Internet connection, you can browse the latest help topics by selecting Help|Microsoft on the Web.
Summary
Perhaps you already can see that Visual Basic is more than it first appears. Programmers use Visual Basic to create extremely advanced Windows applications.

ABOUT THE AUTHOR
Pawan Bangar.
Technical Director.
Ebirbals.
India.