Why Windows and why Visual Basic?
What is necessary for operation with Visual Basic?
Setting Visual Basic
Setup start
Start Visual Basic
Operation with Visual Basic
Simple application
Usage Application Wizard
Operation with the ready project Visual Basic
Sequence of actions by development
The additional information
The given chapter represents the review of Microsoft Visual Basic of version 5 (Further we will name its Visual Basic or is simple VB to distinguish the current version from earlier, we will use abbreviations VB4 or VB3). Now 4 versions of the given language considerably different by possibilities are accessible.
Why Windows and why Visual Basic?
Graphic interfaces of the user, or GUIs, revolutionized the microcomputer industry. They showed that expression "is better for seeing once, than hundred times to hear did not lose the sense for the majority of users of computers. Instead of a mysterious command line. With:> which as long was watched by users DOS, now they look at"desktop"(desktop), filled with tags of programs, controlling them by means of the mouse or by means of the menu.
Possibly, at the durable usage Windows how applications look, less important, something as they are created. In Windows, as a rule, programs have the standard interface of the user. It means that users spend more time for operation with application and less for learning of the menu, dialogue panels and a key pattern (it is finite, Windows applications 95 and Windows NT 4.0 look a little not how Windows applications 3.1: standards are saved in Windows versions, instead of in between).
While programmers have mixed feelings to GUIs, it is pleasant to beginning users, therefore from any programs Windows correspondence of model GUI is expected. Therefore, if it is necessary to develop the program for any of Windows versions, the effective remedy for applications programming with the graphic interface of the user is required to the programmer.
For all this long time there were some such means of development. Before appearance Visual Basic applications programming in 1991 Windows was much heavier than process of an application creation for DOS. Programmers should take care literally about all, for example, about operation with the mouse, menu event handling, and even to trace, the user one or two times in a specific place of the screen clicked. Applications programming Windows demanded expert knowledge on programming in language With and hundreds code lines for performance the elementary of tasks. Problems were even at professionals. (The set of Microsoft Windows Software Development Kit necessary at that time in addition to the compiler With, weighed then about five kilograms).
That is why, when appeared Visual Basic 1. 0, Bill Gates, head and the owner of the company of Microsoft, named it "imposing". Steve Gibson from Infoworld described the given language as "a new magnificent miracle" which strongly changes a sight of people at Microsoft Windows usage ". Stewart Olshop, giving interview to the newspaper" New York Times ", named Visual Basic" an ideal development landscape of programs of 90th years ". Charles Pettsold, the author of one of classical books on programming on With for Windows, wrote in" New York Times ":" For those from us who devoted all life to training to complexities of programming Windows, Visual Basic poses real threat to lose means of subsistence ". The last version Visual Basic continues the given tradition: difficult Windows applications 95 and Windows NT are developed now for much smaller time frame. Errors in programs (bugs) arise not so often, and their localization happens faster and is easier. About Visual Basic programming in Windows does not become more effective, but it becomes more simple (in most cases).
In particular. Visual Basic allows to add to data entry field windows (text boxes), the menu, command buttons (command buttons), switches (option buttons), flags (check boxes), lists (list boxes), scrolling rulers (scroll bars), an also dialog boxes for a file or directory choice. The programmer can use a grid (grid) for handling of tabular data, organize interaction with other Windows applications and access to databases. (By the way, in Visual Basic such components normally name control items.)
On the screen simultaneously there can be some windows. They should have the full access to a clipboard (clipboard) and to the information of the majority of the Windows applications working at the same time. It is possible to use Visual Basic for interaction with other applications working under control of Windows, using the most modern version of technology OLE of firm of Microsoft.
However more and more early versions Visual Basic could carry out to some extent the above described tasks. What the especial it is added to the last version Visual Basic? Briefly the answer consists that Visual Basic supports now elements ActiveX.
Let's an example how the user can load components ActiveX for adding of the useful functions to page Web. We assume that on it the moving picture is allocated and he wants to load it to itself(himself) on the computer and to view. The Microsoft have component ActiveX Movie, to load it it is possible from ActiveX Gallery no for the address www.microsoft.com/activex/gallery, and then to use. Moreover, adding it once to the system, the user should not load it once again. Each time when page Web will contain object "active movie", browser Internet Explorer (and soon and Netscape Navigator) can already use the same element Active Movie from an operating system of the user for video data review.
The majority of the most interesting control items in Visual Basic are elements ActiveX, therefore they can be used without changes in a browser with support ActiveX. Two examples is a grid (grid control) and a control item using one of standard dialogue panels for handling of files. Even elements ActiveX, most powerful of everything, occupy less than 200 kilobyte everyone. More specialized (but nevertheless very powerful) elements ActiveX, are laid down in 20 kilobyte. On one diskette 3,5 it is easily possible to find room for 50 most powerful elements ActiveX.
The sense of all aforesaid consists that if to select one of many new possibilities Visual Basic 5 on purpose to explain, in what its strong difference from early versions it is possible to tell so: "It is possible to build own control items ActiveX completely on the basis of Visual Basic". For the first time programmers on Visual Basic can expand the given language, using only its possibilities. Now they can create the elements ActiveX, thereby using completely all power and simplicity Visual Basic which always were distinctive features of the given language.
At this stage there can be a question on productivity: whether applications Visual Basic 5 more slowly in comparison with earlier versions of language work? The answer will be sensational "Is not present!". Actually professional versions Visual Basic 5 can generate for the first time the executed code (i.e. to create executed EHE-MODULES). Prior versions Visual Basic ???? interpreters. If not to press in differences between the compiler and interpreter VB result is execution of programs Visual Basic 5 with a speed at 10-20 time faster, than it was in prior versions.
What is necessary for operation with Visual Basic?
All versions Visual Basic take a lot of place on a hard disk. Even the small (and the least powerful) free version Control Creation edition demands about 10 Mb of an empty seat on a disk, the processor 486 or Pentium, and also not less than 16 Mb of a random access memory. The full installation of the most powerful version of a Visual Basic Enterprise Edition demands more than 100 Mb of disk space.
Visual Basic it is normally delivered on CD. Free version Control Creation edition can be loaded from the Internet (it about 8 Mb). If you acquired Visual Basic 5, we recommend to fill and send a registration card. Undoubtedly that on electronic mail the certain amount of unnecessary letters comes but so easier to get technical support and notifications on upgraded versions from Microsoft.
Compact disk or diskettes with Visual Basic contain Setup setup. Version Control Creation edition represents a self-unpacked EHE-FILE. All versions demand presence on the computer of Microsoft Windows 95 or Windows NT 3.51 (or their newer versions).
To launch program Setup it is possible so much time, how many it is necessary that means absence of restrictions on a choice of various variants of setting (quite good idea to beginning users - to apply setting by default). At the first setting program Setup requests the user name and the company name. The program saves the given information and deduces its each time at Visual Basic development environment start.
We suppose that you for the life installed enough programs Windows. If one of commercial versions Visual Basic is used, it is necessary to pass to program Setup.??? on a compact disk or on the first to a diskette and simply to launch it on performance. If version Control creation Edition is installed, it is necessary to click twice on a file title VB5Ccein.exe from Windows Explorer. Here ???? to follow instructions on the screen.
After end of procedure of installation Visual Basic it will be installed with own group of programs. For relocation of Visual Basic programs from one group in another or on a desktop it is possible to use Windows Explorer or technology drag-and-drop. For this purpose it is required to study the documentation on Windows or to read the type book "Windows 95 Made Easy" Thom Sheldona.
If there are any additions or corrections to the documentation, they can be found out in a file of type Readme. txt. If the given file is on distributive diskettes or CD, the setup automatically copies it on the winchester and allocates a tag on desktop Windows in group of programs Visual Basic. Now, if twice to click on this tag, Microsoft Windows loads the given file in editor WordPad. It helps to study its contents easily.
The most simple method to launch Visual Basic in Windows 95 or Windows NT 4.0 Start-up consists in usage of point of the Program of the main menu. (The setup automatically adds Visual Basic Start-up in the main menu.) on fig. 1-1 the approximate type of that will be visible on the screen is resulted. Besides, to launch Visual Basic it is possible, passing in its directory by means of a tag "My computer on desktop Windows". Then it is necessary to click twice on a tag Visual Basic. To launch Visual Basic it is possible, opening dialogue panel "Fulfil" from the main menu and entering a way to Visual Basic. (In Windows 95 or in Windows NT 4.0 there is a set of various variants of start of programs.)
When Visual Basic starts to boot, the user sees the screen with the information on copyrights where it is underlined who licenses the given copy of the program. After that on the screen there will be a pattern, approximately corresponding fig. 1-2. (The Exact type of the screen depends on the version Visual Basic.) dialogue panel New Project allows to begin operation on an application creation of Visual Basic any type. In the given chapter one type of application - Standard ??? - abbreviation from the name "the normal independent program" is considered only.
In the given section creation of two applications will be described. We create the first literally manually, it represents a normal window with buttons Maximize, Minimize and Exit. For the second application it will be used Application Wizard (the master of applications), delivered with Visual Basic, applied at creation of interfaces to programs. Such type of applications carries title MDI (multiple document interface). As well as in the normal development landscape delivered about Visual Basic, given applications allow to add windows in a parent window.

Besides, at applications there will be the expanded menu containing a row of standard points: File, Help and so on. Application Wizard generates a considerable quantity of the useful code automatically. Therefore it is required to add only a branching code small amount completely to "recover" created possibilities all automatically. (It is finite, writing of such code demands additional knowledge of programming in Visual Basic. Application Wizard represents powerful, but only auxiliary means of programming; it cannot replace the programmer completely.)
As it was marked earlier, at start Visual Basic its first screen will look how on fig. 1-2. In the dialogue panel New Project shown on fig. 1-2, it is necessary to click twice on tag Standard EXE (it the first in a picture).
The program there and then passes in a mode shown on fig. 1-3. We mark that the empty window bears name Projecti-Form1 (Form). In it there is other window with title Form1 in which the grid from points is visible. It also is the form which can be modified. The grid is used for alignment of control items on the screen, such, as command buttons and lists.
At project start (or its compilations for the purpose of independent start from a Visual Basic development environment), forms, like Form1, become windows which see the user. At the top of the empty form the header row (title bar) with form title (caption) is allocated. As title in Visual Basic is called the text in header row of a specific window. At the moment the form is entitled by default as Form1; such title Visual Basic appropriates to the form in the operation beginning over the new project. To the left of window Form1 on fig. 1-3 the toolbar window (toolbox) in which the control items accessible to layout on the form are visible is allocated. (As it has been marked before, the control item represents the term used in Visual Basic for objects, allocated on the form at its creation.) To the right of a form window three more windows are allocated. Upper carries title Project Explorer. Immediately under it there is window Properties where various properties of the form and control items on it are installed. On the right window Form Layout is below allocated, to tell about which functions it is possible for some seconds.

Now we concentrate attention at a central window with title Project1-Form 1 (Form) and an additional window in it with name Form1. In the majority of applications the Visual Basic size and a location of the form at the moment of the termination of its development (normally it name creation time) define the sizes of that the user sees on the screen at the moment of program operation. It does not mean that in Visual Basic it is impossible to change the size or a location of forms at project start; actually one of the main advantages Visual Basic is possibility to produce dynamic changes in reply to the events generated as response to actions of the user.
Let's change the size of window Project1 to leave more places for operation with the form in it. For this purpose it is necessary to click simply by button Maximize. The result is shown on fig. 1-4.
Now there were more places for operation with window Form1, try to change its size. We describe one of methods of change of the sizes of the form which is the general for all Windows applications. At first it is necessary to click the mouse in the form that it became active. (Always it is possible to define, whether is the window active as its title is selected with color.) then we shift the mouse cursor to any part of a window frame of the form. Thus it should change the type to a bidirectional arrow. From this point on the sizes of the form can be changed, moving the cursor on the screen.
To begin development of the first test application, it is necessary to take following steps:

Let's return to a development landscape, pushing ALT+F4 or clicking under the window menu of control in the form of Form1 twice, or clicking by button Exit in the form of Form1. We mark that current application reacts to all these standard methods of end of operation with program Windows. It shows such important point that in most cases applications Visual Basic behave how user Windows expects, without demanding thus special interference of the programmer (or the user).
Further we try to change a form site, visible to the user it is primary. For this purpose we move window Form Layout in the right lower corner of the screen.
Let's try to drag simply the form in a window on a new place. Then again we start application. It is possible to see that the form window is allocated now there where it dragged in window Form Layout.
The following on what We would like to stop, ? usage powerful VB Application Wizard ("the Master of applications"), entering into all editions Visual Basic, except for Control Creation edition. To launch it, it is necessary to select from menu File|New Project and further, as is shown in fig. 1-2, to select VB Application Wizard. If it is do, after a small time delay on the screen the picture similar to fig. 1-5 will be visible.
For continuation of operation with Application Wizard it is necessary to click by button Next. The following screen is shown on fig. 1-6. Here the programmer can select, as new application will "look". We mark that possible variants on the screen are displayed as words, and in pictures.

To look, as it is all works, it is necessary to click by button Explorer Style. The result is shown on fig. 1-7. The picture shows that in this case the selected style represents a tree structure reminding Windows Explorer (but not Internet Explorer).

Now, nevertheless, value will be used by default at an interface type selection - multiple document interface (MDI). Having convinced that the choice is made, as is shown in fig. 1-6, it is possible to click by button Next. On the screen there will be a window for a menu type selection, as is shown in fig. 1-8.

Again we accept values by default and we click on Next. After that we get to a window where parameters of a file of resources are selected. Now this point in question will not be considered (for the inquisitive we inform that this file allows to change easily names of titles and menu items at change of the international setting, for example, country titles). For passage to fig. 1-9 again it is necessary to click by button Next.

The information on the new screen becomes for the reader of more clear when it studies interaction Visual Basic about the Internet. Now simply we click by button Next. In two following screens it is possible to add some additional forms to application, for example, a window of a picture or the panel "About the program..." (About). However, at present we will not understand with it. Again we click by button Next. There will be a window where it is possible to connect current application to a database. Simply we select button Next.
Here we also reached the last screen, as is shown in fig. 1-10. We click by button Finished and "master" generates the code for new application. (Besides, he asks about necessity of an output of the total form. In it something will be described from this that it is necessary to make still to the programmer. The example of the total report can be seen on fig. 1-11.)
Operation with the ready project Visual Basic
Following step to mastering start of one of examples of the programs delivered ????? with it becomes Visual Basic. (All versions Visual Basic, except for Control Creation edition, are delivered with hundreds examples of programs.

When readers get more close acquainted with Visual Basic, they understand that the given examples represent a good source of the information and the useful ideas.) that example about which speech now goes, shows riches of a choice of the control items delivered together with Visual Basic.
The main steps necessary for loading of the existing project are more low resulted. (We remind that the project represents file set, composable Visual Basic at an application creation, i.e. it is a combination of visual components and the source code.)

After a small pause the project with an example about control items will be loaded in the environment Visual Basic. For its start it is necessary to push F5. (If there is a dialogue panel with a question on necessity to save the previous project, it is necessary to answer "No".) Now the screen will look approximately how is shown on fig. 1-12. After the reader stops to have a good time with the various examples showing capacity Visual Basic by operation with control items, it should click by button Exit or push ALT+F4 for reset to a development landscape.
Sequence of actions by applications programming Visual Basic (the short review)
The author would like to complete the given chapter the short review on a subject how applications Visual Basic are developed. Some steps can seem at first to readers not clear, but very soon all will be explained.

The first step at application programming Visual Basic is planning of that the user sees on the screen, in other words, interface development. What menus are necessary? What window of the size is required for application? How many all will be windows? Whether the user should have possibility to change the sizes of windows? Where to allocate buttons for control of application? Whether in application fields for text entering will be allocated? What type of a control item approaches for the decision of the given task? Whether control items from the given version Visual Basic approach or they are necessary for acquiring or developing?
The amount of the control items, at the disposal of the programmer, depends on edition Visual Basic, and also from a state of its purse or an amount of time spent for their development. In standard edition enters more than 20 control items, into versions Professional and Enterprise - more than 50. Moreover, as Visual Basic pushes independent developers to creation of a considerable quantity of control items for singular problems, almost always it is possible to find a ready element for the decision of any problem. (The Microsoft estimates an amount only commercial control items more than in 2000 units, without considering literally uncountable set free and shareware.) in summary it is necessary to mark the following: to use new possibilities VB5 it is possible, applying or ready control items, or developing them from the very beginning (last, at all respect for the reader, not absolutely suitable method).
Though we still much did not try, but the author wants to repeat once again that finally Visual Basic differs from remaining programming aids simplicity of development of the interface of the user and its communication with the program code. Actually it is possible to draw this interface simply; such approach very much reminds the graphics editor. After interface development is completed, control buttons, fields and other elements allocated on the empty form, automatically will recognize actions of the user, such, for example, as driving of the mouse or click of its button. Visual Basic includes powerful tools of development of the menu that does creation normal and pop up menus by simple business.
Only after the program interface is prepared, the process similar to traditional programming begins. It is the second step at application programming Visual Basic: creation of the program code for activation of the visual interface prepared at the first stage. The sense consists that objects Visual Basic recognize events of type of clicks of the mouse; how they process them, depends on the program code written by the programmer.


Normally the user selects the button, clicking on it the mouse. However sometimes can
To be necessary the big flexibility. One of methods of activation of the button is the general for all
Windows applications: to move focus on the button, pushing TAB, and then to push SPACEBAR. Both
These of a method generate event Click. In other words, Visual Basic causes procedure
Event handlings Click in any of these cases. Event Click can be generated, using the code. (The user knows that the button receiving focus, becomes three-dimensional. It is reached by drawing of a thin dotted rectangle round the text on the button, and a thin rectangle round the button.)
Sometimes it is required to organize interaction with the user on ESC key. Normally
The given key cancels operation or simply deduces the user from the tangled situation.
Thus one of command buttons on the form is activated by ESC key. In a manual on
Visual Basic it carries a title cancel button.
Normally binding of the command button to ESC key is carried out through window Properties, however
It is possible to use and the code. If to view the property list for the command button, it will be found out
Property Cancel. If its value equals True at pushing ESC event will be processed
Click for cancel button even if on it focus is not installed. Setting of value True in property
Cancel for one button means automatic setting of value False for remaining buttons
Forms.
Other possibility - often inconvenient to beginners - setting of the command button on
To default. Thus event Click for such button is generated, when somebody pushes
ENTER key. Here there can be problems as users are inclined to push
The given key during the most unexpected moments. (It happens, as they consider that,
If focus is installed on any object, it is necessary to push not SPACEBAR, namely
ENTER.) anyway if it is necessary to use the given possibility, it is necessary to install
To property Default value True. Besides, on the form there can be some buttons by default.