Introduction to programming in Excel. Visual Basic for Applications programming language - Abstract

1. Left-click on the image of the CommandButton
2. Place the mouse pointer on the created form, the appearance of which will change from an arrow to a cross, and move it to the place on the form where the element being created will be located.
3.Press the left mouse button and move the pointer until the image reaches the required size, after which you release the button - and the object will be created.

We also place the CommandButton2 and Text1 objects on the form. To move an object, you need to select it and move it with the left mouse button to the required position.

Now we need to connect the Microsoft Common Dialog Control 6.0 control component by turning it on in the menu Project--Components and in the list that opens, put a checkmark in front of this component and click OK. After this, the CommonDialog button will appear in the control panel. We also place it on the form. This button will not be visible when saving the application. A pre-created interface view is shown in the figure.

After all the necessary elements have been added to the form, you can begin setting their initial properties, which will determine the appearance and features of working with the interface. These actions are performed using the properties window, which can be displayed if it is not available in the development environment in several ways:
1. By selecting Properties from the View menu
2. Using the Properties Window button on the standard toolbars.
3. By selecting the Properties item in the context menu for the selected object on the form.

At the very top of the window is shown
An opening list of objects shows their properties below.
In our example, the list of objects contains
Form1
CommonDialog
Command1
Command2
Text1
.

Below, on the left side of the column, the properties of objects are shown, and with right side property values. First, select the object, then set the value.

We set the property values ​​for the object according to the table. The property values ​​that we did not change remain the same by default.

An object Property Meaning
Form1 (Name) Border Style Caption StartUpPosition frmDialog 1 - Fixed Single Color and Font 2 - Center Screen
CommonDialog (Name)CancelError dlgStandard True
Text1 (Name) Alignment AutoSize Borderstyle Caption lblExample 2-Center True 1-Fixed Single Sample
CommandButton1 (Name) Caption ToolTipText cmdColor Color Select background color
CommandButton2 (Name) Caption ToolTipText CmdFont Font Select font options

Code. The final stage in creating an interface is writing program code to process it. Editing the program is carried out using the code window for the created form, which can be opened in several ways:
1. Select the Code item in the View menu (in the same way, you can return to editing the form, select the Object item in the View menu);
2. In the Project Explorer, select the name of the form being created and select the View Code item for it in the context menu (you can return to the form in the same way - the View Object item in the form context menu):
3. Double-click on the corresponding form element for which you need to provide processing of any actions. A method for handling this event can be created by double-clicking on the cmdWork element, after which a template for a procedure will appear that processes the user pressing this button.
Open the code editor and enter the data.

Private Sub cmdColor_Click() With dlgStandard On Error GoTo ErrorLabel .Flags = cdlCCRGBInit + cdlCCPreventFullOpen .ShowColor lblExample.BackColor = .Color End With ErrorLabel: Exit Sub End Sub Private Sub cmdFont_Click() With dlgStandard On Error GoTo ErrorLabel .Flags = cdlCFB oth + cdlCFEffects + cdlCFApply .ShowFont lblExample.Font.Bold = .FontBold lblExample.Font.Italic = .FontItalic lblExample.Font.Name = .FontName lblExample.Font.Size = .FontSize lblExample.Font.Strikethrough = .FontStrikethru lblEx ample.Font.Underline = .FontUnderline lblExample.ForeColor = .Color End With ErrorLabel: Exit Sub End Sub

Save the project in the format frm And vbp.This will give you the opportunity to return to the project at any time to change or improve it. Now all that remains is to create the executable file exe in other words, compile the project into a separate file that can work outside the Visual Basic development environment. In the Project menu, turn on the last line - Properties. In the window that opens, in the tab General indicate the project type - Standard EXE and the project name.
In the tab Make indicate the title and, if desired, you can change the icon. In the tab Compile Check the Compile to Native Code box. To make the application run faster, you can enable Optimization for fast code. We don’t need the other tabs. Turn on OK and close the window.

Now let's compile. Open the File menu Do "project name.exe".IN different versions IDE this command may be different, mine is called this, but it can also be Make and Do.

We enable this command and you can check the application by clicking on the menu Start button Start.
It should be under the name and in the place with which you saved it with the extension EXE

See this app in action
Set text and background colors to different ones.



We create our own music player in Wave format.

After you have learned in the first program how to enter commands in the application, we will create your own player. You can save this player on your computer and also modify it for your needs.

Create a new Standard EXE project.
Open the project properties window by selecting Projecti Properties from the Project menu and naming the project MyMultiMedia.

Name the project form Formplayer. In the caption property of the form, enter the title Multimedia Player.

Attach the Microsoft Multimedia Control 6.0 component library to your project using the Components dialog box, which is opened from the Project menu using the Components command.

We'll need a dialog box to search for playable files, so in the Components window, also check the box for the Microsoft Common Dialog Control 6.0 component library.

Add an MMControl control to the Formplayer form by double-clicking the MMControl button in the Controls panel and name it MMControlCDPlayer.

Add a commonDialog control to your form by double-clicking the CommonDialog button in the Controls panel, and name it cdplayer.

Add a CommandButton control to your Formplayer form by double-clicking the CommandButton in the Controls panel. Name this button cbFindFile and set the caption property to Find File. Upon the click event of the cbFindFile button created in the form, a dialog box will open to search for playable files.

Open the code editor and enter code to assign the MMControlCDPlayer control the properties it needs to work with WAV files. Private Sub Form_Load() MMControlCDPlayer.Notify = False MMControlCDPlayer.Wait = True MMControlCDPlayer.Shareable = False MMControlCDPlayer.DeviceType = "WaveAudio" End Sub Private Sub cbFindFile_Click() cdPlayer.ShowOpen MMControlCDPlayer.FileName = cdPlayer.FileName MM ControlCDPlayer.Command = "Open " End Sub Private Sub Form (Cancel As Integer) MMControlCDPlayer.Command = "Close" End Sub

Launch the application by clicking the Start button in the menu. Click the Find File button to open a window allowing you to search, and then select the Wave music file to play. Using the player's control buttons, you can listen to the selected file.
Save the project as in the first application and create an executable file exe

INTRODUCTION

Microsoft Excel has a built-in programming language - Visual Basic for Applications (VBA). This language allows you to create applications that run in the Microsoft Office environment. These can be a variety of analytical programs, financial systems, personnel accounting programs, systems for automatically creating official letters/documents using a library of ready-made templates, etc. In this case, the interface of the program being created may be completely different from the interface of the application in which it is written.

VBA combines virtually unlimited possibilities with ease of learning and use. Now most functions can be described without resorting to programming. If the language capabilities are not enough, you can turn to the Windows API functions. Perhaps the most important advantage of VBA is that this language is the same for all Microsoft office applications and therefore allows you to link them together. Already now, from a program written in Excel, you can access objects in Word for Windows, as well as Microsoft Project. This opens up attractive prospects. Imagine that a user at a specific workplace must, based on some data extracted from the database, analyze it, build diagrams and design the activities of the organization, and also automatically send this processed data to some addresses along with a cover letter. All this can be done using Microsoft office products, but the user must master each of them perfectly. If the program for solving this problem is written in VBA, the user will only have to learn it.

1. Birth and development of Basic

The original Basic programming language was created by John Kemeny and Thomas Kurtz in 1963 at Dartmoor College. It quickly gained popularity as a language for teaching programming in universities and schools and was adapted for use on personal computers by the founder and CEO Microsoft Bill Gates in the mid-70s. Since then, several versions of Basic have been released successively for the PC, including Microsoft Quick Basic and MS-DOS Qbasic. Although the Visual Basic shell is completely graphical, and the programming language itself is very far from the language used for earlier versions of the Basic interpreters, the simplicity and elegance of Basic remains largely inherent in the new versions. The broad capabilities of Visual Basic and its simplicity were the main reason for choosing it as the programming language for creating Windows applications such as Excel.

MS Excel, being a leader in the market for spreadsheet processing programs, determines development trends in this area. Up until version 4.0, Excel was the de facto standard in terms of functionality and usability.

One of the most important functional extensions of the program, intended for professionals, is the Visual Basic (VBA) programming environment built into Excel for solving applied problems. Thanks to VBA, Microsoft was able to not only expand the capabilities of the Excel 4.0 macro language, but also introduce a new level of application programming, since VBA allows you to create full-fledged application packages that, in their functions, go far beyond spreadsheet processing.

2. Brief descriptionVBA

Visual Basic for Applications represents a groundbreaking achievement in programming languages, perhaps the most significant since the release of the first integrated development environment. This does not mean that VBA is the best development tool, but only that VBA exists. Visual Basic is probably the most popular development tool, and now, unexpectedly, the language is included in an equally popular application suite.

Since Microsoft applications are based on the same programming language, it is likely that many people will think of using it. Just as Windows users need to master one interface to create many programs, VBA only requires learning one programming environment to create a variety of applications. About 40 software companies have entered into an agreement with Microsoft to include VBA in their products. The first of these companies to enter the market was Visio Corp., which integrated VBA into Visio Professional and Visio Technical, version 4.5. You can expect such firms to aggressively market VBA because their products have benefited significantly with this language. VBA's real name is Visual Basic Application Edition, and it actually belongs to the VB family, hence attracting increased interest as a tool in its own right.

Embedding VBA into an application means creating an object model for it, as a result of which the VBA program can access and manipulate the objects of this application. For Visio products, these objects can include both the rectangle in the drawing and the drawing itself, and the object model extends to all of these elements.

And an application with an object model and VBA is already part of the developer’s arsenal. Suppose, for example, that you wanted to write a program that could help you prepare a layout of furniture and equipment in your kitchen and then print out a list of items and prices. This program requires a database with information about kitchen furnishings and some way to visualize an image of the kitchen.

Just as you can create an Office macro that accesses Word and Excel, you can create a VBA program that combines Access and Visio. A composite kitchen planning application can be considered a hybrid of Access with a drafting engine or Visio with a database.

VBA is its own subset of VB5, but in fact VBA has almost everything that can be found in VB5. It must be admitted that there are still minor differences (for example, launching from Word, and not in offline mode), but in any case the programming is the same. Office 97 object models are only valid as long as the applications that own them are running, so both VBA and VB5 can manipulate them. Vs We see that the integrated development environment in VBA is almost no different from that in VB5.

3. New features of Visual Basic 5.0

    Managing Multiple Projects Using Explorer

    Using new Code Editor environments, including Auto Quick Info

    Working with the Form Layout window for customization appearance programs.

    Resize windows and documents.

    Selecting and using Active X control features.

    Use of new debugging tools and techniques to correct programming errors.

    Quickly start a project with one or more predefined forms.

    Extension Microsoft capabilities Word through automation.

The Visual Basic programming environment contains all the necessary tools for quickly and efficiently creating powerful programs that run in the Windows environment.

The tools available in the Visual Basic programming environment help in constructing Basic programs.

The Menu Bar provides access to most of the commands that control the programming environment. Menus and commands operate according to standard conventions common to all Windows applications.

Below the menu bar there is a toolbar - a set of buttons that are shortcuts to commands that are used to work in the Visual Basic environment. At the bottom of the screen is the taskbar. It can be used to switch between Visual Basic components or to activate other Windows applications. There is also a Toolbox window, a Project Container window, a Form window, a Project window, an Immediate window, a Properties window, and a Form layout window.

Visual Basic project files have extensions. vbp, wak, vbg in the file name.

There are 7 tools in the Visual Basic environment.

A Visual Basic form is a window in the user interface.

Tools and controls on the panel are used to add new user interface elements. The toolbar also contains controls for creating objects that perform special “on-screen” operations: managing information in the database, controlling time intervals, etc.

Properties Window

The Properties window allows you to change the characteristics (settings) of user interface elements on a form. The properties window contains a list of all objects used in this user interface. It may also list the property settings that can be changed for each object.

Project window.

Visual Basic - A program consists of several files that are put together when the program is ready. The Project window lists all the files used in programming.

Project files contain a list of all supported project files and programs and their vbp (Visual Basic program) extension.

In Visual Basic 5, you can load multiple project files at once into the Project window.

Visual Basic provides online help that includes information about the programming environment, tools, and the Visual Basic programming language.

Controls. With their help, objects and forms are created, information is displayed in a text block, drives and folders in the system are viewed, data entered by the user is processed, Windows applications are launched, and database records are viewed.

Visual Basic language.

The Visual Basic programming language contains several hundred instructions, functions, and special characters. It is not only intended for use in software product Visual Basic, Microsoft Visual Basic for Application is included with Microsoft Excel, Microsoft Word, Microsoft Access, Microsoft PowerPoint, Microsoft Project, and other Windows applications.

4. EXAMPLE OF INTERACTIONEXCELAND VISUAL BASIC

Starting with version 5.0, Excel included a special programming language called Visual Basic for Applications (VBA).

The introduction of a fairly powerful programming language in Excel makes this software platform very attractive to professionals who develop specialized application systems.

The development of the VBA programming language, embedded in application systems, is one of the strategic directions of Microsoft. This language is already integrated into programs such as Word for Windows, Power Point and a number of others. VBA allows you to create program modules, menus, dialog boxes, and other resources in the Windows environment. Thanks to this language, it becomes possible to significantly expand the set of functions in Excel, as well as create functions whose values ​​depend on certain conditions and events. In principle, you can completely reprogram all functions of Excel if the need arises.

5. Programming table functions

To create a separate worksheet for a software module, click on the icon Insert Module from the Visual Basic icon menu (1st icon) or call the directive Module from the menu Insert Macro. After this, a new worksheet "Modele1" will appear. In a program module, you need to describe a function in VBA. You can work in the window of a program module as in the window of a small text editor, but you must remember that you are writing the text of the program. A function description must begin with a Function statement, followed by a space separated by the name of the function and its arguments, enclosed in parentheses and separated by commas. Then comes the actual text of the function’s program code, and the description should end with the End Function statement.

If in the text of the program code the name of the function being defined is on the left side of the assignment operator (denoted by the equal sign), then the assigned value will be the result of calculating the function with the given arguments. As an example, consider a function that calculates value added tax.

Function NDS(Value)

6. Function Inlining

Click on the 3rd icon Object Browser from the VBA icon menu or call the directive of the same name from the menu View.

User-defined functions are treated as independent objects in Excel. In the list box Methods/Properties: will contain the name of the new function. Click first on the name and then on the command button Options, then a dialog box will open Macro Options. In field Description: Enter explanatory text that will later be used by the Function Builder. On the list Function Category indicate the category in which you want to record your function. For example, a function that calculates value added tax should be placed in the category Financial. In the future, the Function Builder will place your function in the category you specified. Close the window Macro Options by clicking the command button OK, and the window Object Browser- button Close.

7. Application of functions

Go to the worksheet where the table will be located. Move the cell pointer to the cell that will contain the formula and enter an equal sign in it. Then click on the 14th Function Builder icon on the main icon panel.

The Function Builder dialog box appears. In the first step, select a category Financial and in the right field find your NDS function. Click on the name of this function, then proceed to the next step by clicking on the command button Next.

A second Function Builder dialog box opens. Here you can see your comment on the function, which was entered earlier in the macro options window. Provide a single argument to this function, Value, and close the Designer dialog box by clicking the button Finish.

A value that is 15% of the argument value will appear in the table. In a table, you can work with this function as with a regular Excel function.

8. Variables and operators

Visual Basic allows you to reserve variables, with or without size, work with various data types, use constants, work with mathematical operators and functions, and use additional operators. The use of loop operators For Next, Do, and objects of the “timer” type (an invisible stopwatch in the program) is provided. The accuracy of setting the time in the program is 1 millisecond, or 1/1000 sec. The started timer is constantly running - i.e. the corresponding interrupt handling procedure is executed at a specified time interval - until the user stops the timer or disables the program.

Data types

Size (bytes)

Range of values

Usage example

Integer

from - 32768 to 32767

Long Integer

from - 2147483648 to 2147483647

Single-precision Floating paint

from - 3.402823E38 to 3.4402823E38

Double-precision Floating paint

from -1.79769313486232D308 to 1.79769313486232 D308

Dim pi# pi#=3.1415926535

Currency (currency units)

from -922337203685477.5808 to 922337203685477.5807

Debt@=7600300.50

String

1 per character

from 0 to 65535 characters

Dog$=’pointer’

Boolean

True (true) or False (false)

Dim Flag as boolean

from January 1,100, to December 31.9999

Dim Birthday as Date

Birthday=#3-1-63#

Variant

16 (for numbers); 22+1 per character (for strings)

for all data types

Action

Returns the absolute value of n

Returns the arctangent of n in radians

Returns the cosine of angle n in radians

Returns the constant e to the power of n

Generates a random number between 0 and 1

returns -1 if n 0

Returns the sine of angle n in radians

square root of n

Converts a numeric value to a string

Returns the tangent of an angle n in radians

Converts a string to a numeric value

9. Using OLE Forms and Controls

Forms can be modal or non-modal.

Visual Basic has a very flexible system for using forms. You can make all the forms in a program visible at the same time, or you can load and unload forms as needed.

A modal form is a form that should always be used when displayed on the screen, it remains in the foreground until the user clicks OK, Cancel, or submits it.

A form that the user can disable is called non-modal (informal). In most applications Microsoft Windows Modeless forms are used to display information because they provide greater flexibility, so the form is set to modeless by default when a new form is created. You can also set any property for the form, including title, size, border type, background and character colors, text font, and background image.

Visual Basic allows you to:

    work with controls

    work with menus and dialog boxes

    work with forms, printers and error handlers

    add artwork and special effects

    use modules and procedures

    work with sets of elements and arrays

    to Work with text files And databases

    interact with Microsoft Office

Visual Basic provides three very useful objects for providing access to file system. These are lists of disk drives that allow you to scroll through the available disks in the system; directory lists that allow you to navigate through folders on the selected drive, and file lists that allow you to select the desired file in a folder.

Using Data Objects to Browse Databases Microsoft data Access.

To work with databases, Visual Basic provides three objects that allow you to display and change information in database files. The data object gives access to the fields and records of the database file directly on the form. The object also allows you to change information in the database.

If you regularly work with databases - especially Microsoft Access, Microsoft FoxPro, Paradox, Brieve and dBase - then Visual Basic will prove to be a very powerful tool for processing and displaying data. Since Visual Basic provides database processing technology similar to that used by Microsoft Access, you can create basic applications for working with databases using just a few dozen lines in the program text.

Visual Basic can read and write information to a database in various formats.

Using Visual Basic, you can build your own database application that displays only the information the user needs and also provides the user with the necessary tools to process the data. The Line and Shape controls allow you to create geometric shapes.

You can use OLE to insert objects from applications into Visual Basic programs. Examples of application objects include Excel sheets and charts, Word documents, and Microsoft ClipArt images. Application objects can be either new, uninstalled documents or existing facts loaded from disk.

In Visual Basic, you can create both object-based and control applications that support the Automation feature.

Windows applications that fully support Automation allow you to access their functionality as a collection of objects with their associated properties and commands. Windows applications that provide properties of objects are called object or server applications, and programs that use these objects are called control or client applications. Automation is an industry standard that allows two applications to interact.

Conclusion

Not so long ago, the mention of Basic as a programming language caused only a condescending grin (and sometimes indignation) from most professional software developers. This was explained simply: “Yes, there is a language that is used by amateurs (if not to say “dummies”). But putting “Vasik” on a par with real programming tools is simply ridiculous.”

Nowadays, hardly anyone would dare to express such an opinion: over the past years, Microsoft Visual Basic (VB) has become the most popular application development tool in the world. Moreover, knowledge of its basics today is actually mandatory for all programmers, no matter what tools they use. This is due to two interrelated factors. Firstly, VB is very widespread and is used not only as a stand-alone tool, but also as a programming system built into numerous application programs (MS Office in particular). Secondly, having turned into a serious professional tool, VB has remained a very convenient tool for learning programming and solving small problems.

LITERATURE

1. "Information technologies. Tutorial". Edited by A.K. Volkov. Moscow. Publishing house "INFRA-M". 2001

2. "Informatics: Textbook" Ed. prof. N.V. Makarova. Moscow. Publishing house "Finance and Statistics". 2005

3. "Information management technologies: Textbook." Edited by Yu.M. Cherkasova. Moscow. Publishing house "INFRA-M". 2004

4. "Informatics". V.A. Ostreykovsky. Moscow. Publishing house "Higher School". 2004

5. "Legal informatics course." Gavrilov O.A. Moscow. Publishing house "INFRA-M". 2006

For self-study Visual Basic language allows you to understand the basics of programming from scratch without the help of a teacher and learn how to create full-fledged applications for Windows. The large amount of information about Visual Basic also makes it possible to use the book as a reference.

* * *

The given introductory fragment of the book Visual Basic for Beginners. Step by step. Tutorial/reference book (Evgeniy Matveev) provided by our book partner - the company liters.

Chapter 2: Introducing Visual Basic

In this chapter you will learn:

Launch Visual Basic,

Find the menu items you need,

Use the toolbar buttons

Understand all the main interface objects,

Create application projects,

Choose the right one application type,

Save and open recorded projects,

Write your first program

Use the help system correctly.

2.1. Programming Environment Overview

Mainly Windows menu select team Start – Programs – Microsoft Visual Studio 6.0 – Microsoft Visual Basic 6.0(Start – Programs – Microsoft Visual Studio 6.0 – Microsoft Visual Basic 6.0) Visual Basic will start and a dialog will appear on the screen New Project(New Project) expanded in the tab New(New) (Fig.2.1).


Fig.2.1. New Tab


Dialogue New Project(New Project) offers the user the option of creating a new one or opening an existing project. Project is an application under development. It consists of several components stored on disk as separate files, each of which has a corresponding extension:

Form files with source code (*.frm),

Form files with executable code ( *.frx),

Module files ( *.bas),

Class module files ( *.cls),

Additional control files ( *.ocx),

Project file ( *.vbp),

Resource file ( *.res),

Other files.

By selecting one of the icons on the tab New(New), you can create a new empty project of the desired type or use the services of one of the application generation wizards.

At the end of the wizard, a draft version of the application is obtained with ready-made forms, menus, toolbars, etc. Then the programmer has to finalize many small details, but thanks to the use of the wizard, time is saved on building the main framework of the application.

Now let’s list the options for created applications or components that are selected on the tab New(New) dialogue New Project(New project):

Standard EXE– standard application,

ActiveX EXE– ActiveX component as an application,

ActiveX DLL– ActiveX component in the form of a dynamically loaded library,

ActiveX Control– an ActiveX component in the form of a Visual Basic tool for creating controls,

VB Application Wizard– Visual Basic Application Wizard,

VB Wizard Managercontrol program on creating custom wizards,

Data Project– application for working with databases,

IIS Application– application for Microsoft Internet Information Server,

Addin– add-on for Visual Basic,

ActiveX Document Dll– ActiveX document in the form of a dynamically loaded library,

ActiveX Document Exe– ActiveX document as an application,

DHTML Application– application in the form of a dynamic web page,

VB Enterprise Edition Controls– a standard Windows application with the ability to use additional controls.

To view the next dialog tab New Project(New Project) click on the shortcut Existing(Existing) (Fig.2.2).


Fig.2.2. Existing Tab

New Project dialog


Tab Existing(Existing) allows you to open a saved project from any permanent or removable drive, or network device, for which first select the folder where it is located in the drop-down list Folder(Folder), then the project file name in the main window and click Open(Open).

Now let's go to the tab Recent(Recent) dialogue New Project(New project) (Fig.2.3).


Fig.2.3. Recent Tab

New Project dialog


Here you can quickly return to one of the most recently edited Visual Basic projects by simply clicking on the project file name and clicking Open(Open).

To continue to familiarize yourself with the Visual Basic programming environment interface, you should create a standard application project. In this case, most menu items and toolbar buttons will become available.

Return to tab New(New) (Fig.2.1) dialogue New Project(New Project), click on the icon Standard EXE (Standard application) and press the button Open(Open). After this, a new project will be created with the name Project1, which is assigned by default, and we will see the Visual Basic programming environment in the mode design(design) (Fig. 2.4).

Fig.2.4. Visual Basic programming environment

in design mode


We list the objects of the interface of the Visual Basic programming environment that are currently visible:

window title(Window Header)

menu bar(Menu Bar)

toolbar(Tool Bar)

control panel(Tool Box)

project guide(Project Explorer)

properties window(Properties Window)

form placement window(Form Layout Window).

Window title(Window Header) displays the name of the project being edited and current mode work of Visual Basic, as discussed above.

Menu bar(Menu Bar) provides the programmer with the opportunity to use a powerful arsenal of functions of the Visual Basic programming environment (Fig. 2.5).


Fig.2.5. Menu Bar Functions


Right below the menu bar, like many Windows applications, is toolbar(Tool Bar), the buttons of which duplicate the most frequently used Visual Basic menu items. The toolbar also displays reference information about the position and size of the selected object, or the location of the cursor in the program text (Fig. 2.6).


Fig.2.6. Tool Bar Functions


On the left side of the Visual Basic window is control panel(Tool Box) (Fig.2.7).


Fig.2.7. Tool Box


Most of the controls are used to design the appearance of the application and interact with the user. They will be discussed in detail in the corresponding chapter.

There is a window in the upper right corner project guide(Project Explorer) entitled as Project - Project1(Project – Project1). This window has a tree structure with a list of components that are part of the application being designed. Now the list contains one single component - a form named Form1 (Fig. 2.8).


Fig.2.8. Project Explorer


If you right-click on an object name in the Project Explorer, a context menu will appear from which you can select required action over this object, for example:

Print on a printer,

Because Visual Basic applications are built in a modular fashion, each project component is stored in a separate file.

Below is properties window(Properties Window), which has a title Properties – Form1(Properties – Form1) (Fig.2.9).


Fig.2.9. Properties Window


Using this window, you can view or change the property values ​​of various controls that are on the form, as well as the form itself. The properties can be very different: name, size, color, etc.

Under the window title there is a drop-down list containing a list of controls for the active form. Even lower, you can see a list of properties of the selected element in the form of a pair: the name of the property – its value. For example, property Caption(Title) matters Form1.

To make it easier to navigate large quantities information, the property list has two tabs that allow you to select the sort order: Alphabetic(Alphabetical) or Categorized(By category). Finally, below the list of properties is a tooltip about the purpose of the property highlighted by the mouse click.

The next window we'll look at is form placement window(Form Layout Window) (Fig.2.10).


Fig.2.10. Form placement window

(Form Layout Window)


It displays a small copy of the worker Windows desktop with the form located on it exactly as it will be while the program is running. Particularly valuable is the ability to check the location of a form on the desktop at different resolutions.

All subwindows are docked to the edges of the main Visual Basic window. This type of interface is called (Multi-Document Interface). Early versions of Visual Basic used another variation called Single Document Interface, where each child window was independent.

If you want to install a different interface type, select the menu command Tools – Options…(Tools - Options...). A dialog will appear Options(Options), where you need to go to the tab Advanced(Optional) (Fig.2.11).


Fig.2.11. Advanced Tab

Options dialog


After checking the box SDI Development Environment(Single Document Development Environment) and button clicks OK, the interface type will change to SDI – Single Document Interface(Single Document Interface).

You can adjust the docking behavior of individual child windows when using MDI – Multiple Document Interface(Multi-Document Interface), for which you should go to the tab Docking(Attaching) the same dialogue (Fig. 2.12).


Fig.2.12. Docking Tab

Options dialog


Selecting the checkbox to the left of the name of the corresponding subwindow enables Visual Basic to snap to the edge of the main window, and clearing the checkbox disables it.

In addition to the interface objects of the Visual Basic programming environment, approximately in the middle of the screen (Fig. 2.4) there is a window for the created project, which has a title Project1 – Form1 (Form)(Project1 – Form1 (Form)), inside which is the displayed form of the future application (Fig. 2.13).


Fig.2.13. Form Form1

in the Project1 project window


The form is a separate window of the future application. Elements can later be placed on its surface Windows management: buttons, text input fields, lists, checkboxes, etc.

The grid of small dots is visible only during application development and helps the programmer to proportionally place controls on the form.

The same form in runtime will look slightly different, without a guide grid for placing elements and a project window (Fig. 2.14).


Fig.2.14. Form Form1

in runtime


The form plays a key role in the vast majority of applications created with Visual Basic. Except visible interface, it contains event-handling routines that are executed when form buttons are clicked, keystrokes are pressed, and other user interactions with elements located on the form.

Most other components of the Visual Basic programming environment are also, to one degree or another, related to the form and contain its name in their name, so it is advisable not to rename the form to avoid the need to manually rename other program components.

Some Visual Basic interface windows are not visible by default. You can control their display on the screen using menu commands View(View). One of the most important is Code Window(Code window), in which the source code of the subroutines included in the application is entered.

Execute menu command View - Code(View – Code), after which you will see the code window (Fig. 2.15).


Fig.2.15. Code Window

(Code Window)


Another commonly used window is Object Browser(View objects), where you can not only view a hierarchical list of available objects, but also see brief information about their use in the program (Fig. 2.16).


Fig.2.16. Object Browser

(View objects)


The remaining windows of the Visual Basic programming environment will be discussed in the corresponding chapters.

2.2. Help about objects and their properties

There are quite a lot of objects in Visual Basic, and they have even more properties. Remembering everything is difficult, if not almost impossible, so you need to constantly use the built-in help.

The same goes for instructions and built-in functions of the Visual Basic language. Of course, they will be memorized gradually, but don’t worry if you don’t remember exactly the name or syntax of some instruction.

The context-sensitive help of the Visual Basic programming environment can be easily accessed on the screen using the key .

Help is called context-sensitive because the Help topic that is displayed depends on the current context, which is determined by the selection of any object and the name of the Visual Basic property, method, or statement within which the text cursor is positioned.

Let's try to use Visual Basic context help in practice. For example, we want to get detailed information about the control ProgressBar(Progress bar).

Select the button with the mouse ProgressBar(Progress bar) in ToolBox(Toolbox) and press the key . A Visual Basic help window will open with information about this object (Fig. 2.17).


Fig.2.17. Visual Basic Help - ProgressBar


At the top of the description text, just below the current section title, there are several menu options you can select to get more information:

See Also(See also) – information on related topics,

Example(Example) – text code examples,

Properties(Properties) – list of properties,

Methods(Methods) – list of methods,

Events(Events) – list of events.

Let's say that we need to familiarize ourselves with examples of programming a control ProgressBar(Progress bar).

In theory, we should have selected the item Example(Example). But in in this case This item is not available because the code examples are located below. Therefore, move down the text using the vertical scroll bar until you see an example procedure using the control ProgressBar(Progress bar) (Fig.2.18).


Fig.2.18. Visual Basic Help - Example procedure text using ProgressBar

(Progress bar)


All examples that are available in the Visual Basic help system can be used as a sample, for which you can copy them into your program and edit them at your discretion.

Select the desired part of the code with the mouse and copy it to the Windows clipboard using the keyboard shortcut +[C] or + .

Go to your program and press the key combination +[V] or + to insert a code snippet.

While in the Visual Basic Help window, you can browse the contents of other topics, or use the index or search to find the Help topic you're looking for.

To find the information you need, click on the label Search(Search) located on the left side of the Help window. The tab will open Search(Search) Visual Basic help system (Fig.2.19).


Fig.2.19. Search Tab

Visual Basic Help


Click on the input field Search for following words(Search for the following words) and enter keywords to search, using logical operators if necessary: And(AND), Or(Or), Near(Close), Not(Not). Entering these operators is possible not only manually, but also by selecting from a list called up by clicking on the button to the right of this field.

To start searching for help topics that contain the keyword combination you entered, click Topics(Sections) and wait for the search process to complete. Upon completion, a list of found partitions will be displayed on the left side of the window.

The help options described above are available from the Visual Basic menu. The help content is called by the command HelpContents…(Help - Contents), alphabetical index - the next paragraph HelpIndex…(Help - Index), and search - HelpSearch…(Help – Search). Using the menu Help You can also go to the Microsoft Web site for technical support.

2.3. First application in Visual Basic language

Now let's try out in practice the entire process of developing an application using Visual Basic using the example of the simplest program Hello, World! (Hello World!). This application will only have two buttons: Greetings And Exit.

After pressing the button Greetings a dialog with a message should appear Hello World!, and after pressing the button Exit– the program exits.

The well-known Hello, World! (Hello, world!), usually written by all novice programmers taking their first steps in mastering a new programming language.

To continue the development process of this program, we will use the already created project with the default name Project1, just rename it first.

From the Visual Basic menu, select Project-Project1 Properties…(Project – Project1 Properties…). A settings dialog will appear on the screen (Project1 – Project Properties), opened on the tab General(General) (Fig.2.20).


Fig.2.20. General Tab

Settings dialog Project1 – Project Properties

(Project1 – Project Properties)


Double click on the input field Project Name(Project name) and replace the existing text Project1 on new - HelloWorld. After that, click the button OK to close the settings dialog Project1 – Project Properties(Project1 – Project properties).

Let's rename the only form of our application. To do this, click anywhere on the form Form1, after which in the window Properties – Form1(Properties – Form1) a complete list of its properties will be displayed (Fig.2.21).


Fig.2.21. Properties Window – Form1


In the left column of the properties window, find the property called Name(Name) having the current value Form1. Property name Name(Name) is enclosed in parentheses because it is used slightly differently in Visual Basic code than all other properties.

Name(Name) in the right column and enter Hello World, then press the key .

Change the property value in the same way Caption(Headline). Instead of the old value Form1 enter new - Hello World! Please note that you can already use spaces, commas and other characters here. The form will take the following form (Fig.2.22).


Fig.2.22. HelloWorld form in the HelloWorld project window


How are these two properties different? Property Name(Name) is required for any Visual Basic object. It uniquely identifies or, in other words, points to this object so that it can be accessed from the program text. Form name Hello World can be seen in the title bar of the current project window: HelloWorld – HelloWorld (Form). This window is for informational purposes only and is only displayed in application development mode. The project window contains the form itself inside Hello World.

Property Caption(Title) is only available for those objects that can have a caption visible on the monitor screen, for example, for objects Form(Form), CommandButton(Command button) or Frame(Frame). Our form has the inscription Hello World! can now be seen in the title bar, where it will also be visible when the application runs.

Now everything is ready to continue designing the interface of our application, which consists of one form on which two buttons should be located. We already have the form. All that remains is to place buttons on it and write a subroutine for displaying a dialog with a message on the screen Hello World!

Placing a button on the surface of a form is similar to drawing a rectangle in standard program Paint. Click the tool icon CommandButton(Command button) of the control panel (Tool Box) and position the mouse pointer over the form, which will change to a cross:

Press the left mouse button and, while holding it in this position, move the mouse pointer a couple of centimeters to the right and down from this point, and then release the mouse button. A command button with the inscription will appear in the specified place on the form Command1.

Place the second button on the form in the same way. After this, it will take approximately this form (Fig. 2.23).


Fig.2.23. HelloWorld form with two command buttons


Of course, it is difficult to immediately establish the required sizes and location of buttons. But Visual Basic then allows you to change these settings in several ways that are common to all controls:

With a mouse control selected, you can drag it across the form's surface or resize it by grabbing one of the square handles around its perimeter.

To more accurately set the geometric dimensions of a control element, select it and set the numeric values ​​of the properties Left(Left), Top(Upper), Width(Width) and Height(Height) in Properties Window(Properties window). The first two properties indicate the coordinates of the left top corner control, and the latter – the width and height of the object.

Now let's change the labels on the buttons that should not be Command1 And Command2, A Greetings And Exit accordingly, and also give more informative names to these objects.

Click to highlight the button Command1, after which in Properties Window(Properties window) a list of its properties will be displayed.

Double click on the property value Caption(Heading) and instead Command1 enter Greetings. After this, the text on the button will immediately change.

Change the property in the same way Name(Name), setting it to a new value – cmdHello.

Perform similar actions with the button Command2, which has properties Name(Name) and Caption(Header) assign values cmdExit And Exit respectively.

At this point, the interface design stage ends, and we move on to actually writing the program text.

Double-click the button labeled Greetings. A code window will open with the already designed subroutine template cmdHello_Click, which will be called when you click on this button (Fig.2.24).


Fig.2.24. Code window with cmdHello_Click procedure


The Visual Basic code window, except for the main part intended for entering the text of individual subroutines and global settings form, contains two drop-down lists.

In the left list you can select a control element, and in the right list - the type of event to respond to which you plan to write a subroutine in Visual Basic.

After selecting both values ​​in the drop-down lists, an empty procedure for handling this event will be automatically created in the main part of the code window.

In this case, the desired control and event type are already selected. This is a button with the name cmdHello and event Click(Click). The text of an empty event procedure looks like this:



Keyword Sub, abbreviation for Subroutine(subroutine), serves for ads(Declaration) procedures cmdHello_Click, which handles the button click event cmdHello.

The name of the procedure consists of the name of the object, the underscore character " _ " and the type of the event. It is this name that indicates to Visual Basic that this procedure is associated with the event Click(Click) buttons cmdHello. Empty parentheses tell us that no parameters are passed to the procedure.

Modifier Private(Private) indicates that this procedure is visible only within its container, in this case the form. The instructions complete the procedure. End Sub.

Of course, an empty procedure does absolutely nothing - in order for it to do anything, you need to write at least one line of program inside the body of the procedure.

From this moment the process begins coding(Coding), which is the writing of the text of a program that performs the desired functionality.

Coding is the central link of any programming system. Visual Basic is no exception, although it allows you to minimize your coding time.

All we have to do is enter a single Visual Basic language instruction inside the procedure, which displays a dialog with a message Hello World!:


MsgBox("Hello world!")

The finished procedure will then look like this:


Private Sub cmdHello_Click()

MsgBox("Hello world!")


Then double click on the second button that says Exit. The procedure for processing the event of clicking on this button will open.

In the body of the procedure cmdExit_Click enter instructions End, which performs the function of shutting down the application when an event occurs Click(Click).

The text of the second procedure will now look like this:


Private Sub cmdExit_Click()


That's all! All that remains is to admire the work done, checking the functionality of the written code.

To check the viability of the created program, click on the button Start(Launch) toolbar or press the key .

Visual Basic goes into run mode and a running Hello, World! application appears on the screen. (Hello, world!) (Fig. 2.25).


Fig.2.25. Working application

Hello, World! (Hello World!)


Make a few clicks on the button labeled Greetings. A dialogue will appear with the required text message(Fig.2.26).


Fig.2.26. Dialogue with text message

Hello, World! programs (Hello World!)


Admire it with the pride of the creator of your first computer program and press the button OK to close the dialog.

Now click on the button Exit. The program exits and Visual Basic returns to design mode.

2.4. Saving a project to disk and loading it

to continue programming

The author has no doubt that creating applications using Visual Basic will captivate you and there will be a need to save the project on disk, as well as then load it to continue working. This is very easy to do, similar to saving Microsoft document Office.

Just click the button Save Project(Save Project) toolbar (Tool Bar), or select the menu command FileSave Project(File – Save Project) to save all project components to disk. Visual Basic will then prompt you to save the individual components one by one. The dialog will appear first Save File As(Save file as) with a request to save the form (Fig.2.27).


You can edit the suggested form name in the input field File Name(File name) or leave it unchanged. Then click the button Save(Save). After saving the form, a dialog will appear Save Project As(Save project as) with a request to save the project (Fig.2.28).


This will complete saving the project. When you save again, you don’t have to do all the steps again - just press the button Save Project(Save Project) toolbar.

There is another more flexible option for saving individual project components, which may be necessary, for example, if changes to other components do not need to be saved.

Expand the thread Forms(Forms) by clicking on the icon. Here we will see the name of the form Hello World(Fig.2.29).


Fig.2.29. HelloWorld Project Components Overview

in the Project Explorer


Right-click on the form name. A context menu will appear, with which you can perform all valid actions on this object (Fig. 2.30).


Fig.2.30. Context menu

in the Project Explorer


Select menu item Save HelloWorld.frm(Save HelloWorld.frm) to save the form to disk.

To configure the automatic saving mode of the project, use the menu item Tools – Options(Tools - Options). A dialogue will open Options(Options). Click on the tab Environment(Wednesday) (Fig.2.31).


Fig.2.31. Environment Tab

Options dialog


Switch When a program starts(When the program starts) set to Save Changes(Save changes) and click the button OK.

That's it for saving the project. Now let's try loading the saved project from disk.

To open a project, select the menu command File – Open Project…(File – Open project...). A dialogue will appear on the screen Open Project(Open Project) expanded in the tab Existing(Existing) (Fig.2.32).


Fig.2.32. Existing Tab


First in the dropdown list Folder(Folder) select the drive and directory where the project is located, then click on the file name and click the button Open(Open).

If you have already worked with a saved project before, then it is more convenient to open it a little differently. Click on the shortcut to go to the tab Recent(Recent) dialogue Open Project(Open project) (Fig.2.33).


Fig.2.33. Recent Tab

Open Project dialog


On this tab you don't need to select a folder, just click on the project name and click the button Open(Open).

One way or another, we have opened the desired project, but Visual Basic itself will not display the forms on the screen for editing; for this they need to be displayed deliberately.

To display it, double-click on the form name Hello World in the Project Explorer window (Fig. 2.29), or first right-click on it, and then select the item from the context menu that appears (Fig. 2.30) View Object(View object).

Visual Basic 6.0 - Tutorial for beginners - Lukin S.N. - 2001.

This is a tutorial. That is, the book was written with the expectation that, having studied it without outside help, you will be able to compose programs in Visual Basic without outside help and run them on a computer, also without outside help. The author has made special efforts to make the presentation clear. Everything is explained with examples. Consideration of almost every topic ends with tasks for drawing up a program (there are 132 such tasks in total). The vast majority of problems are provided with answers, so that the reader can effectively control the assimilation of the material.
If you want to learn how to program, but have never written a single program in your life and have little idea how a computer works, read this book from beginning to end - you will learn how to program and learn everything you need about the structure of a computer.

If you are interested in programming games, then know that this book is aimed at exactly that. Having studied it, you will be quite ready to create your own games such as sea battles, tic-tac-toe, tank battles (where many tanks move along a square field), and shooting games. However, more details about the games are below.
Let's assume that you are a high school student or a student studying Visual Basic programming for the first year, and you are about to take an exam on it. You feel like you are “at zero” and UNDERSTAND NOTHING and don’t even know where to start. In this case, after studying the book and completing the tasks given in it, you will have a solid understanding of the basics of Visual Basic. Is that enough?. After all, Visual Basic is a rich Christmas tree with a great variety of toys. My book tells you everything a beginner needs: about the trunk and main branches of the Christmas tree, how toys are attached to the branches, and the most interesting toys. However, where is the guarantee that your teacher does not prefer others? Maybe take a thicker book?
If you take any of the thickest books on Visual Basic, then you probably won’t find everything that is required of you. There are too many toys in Visual Basic even for a three-volume book. So first learn the basics of Visual Basic with a book like this one. Then either try to find a thick book that talks specifically about what you need, or use the Help system for this. It is difficult to read a thick book right away - it is usually not intended for beginners, even if it says otherwise. However, you may not need a thick book - this book covers everything a reasonable teacher could ask in the first year of teaching.
If you are an experienced programmer in visual program development environments, but also want to learn Visual Basic, you do not need this book - the presentation is intended for beginners.
If you don't have a computer at hand, then things are bad for you. Without a computer, using only one book, you can only learn to write program text on paper. Of course, this is not a little, but it is reminiscent of reading a recipe for a luxurious steak on an empty stomach, when the refrigerator is empty. In the visual development environment for Windows, which is Visual Basic, program text is not everything.
The book teaches not only how to write programs, but also how to execute programs on a computer. All you need to know in advance is where the computer's power button is. Everything else in the book is explained, including instructions for installing Visual Basic on your computer.

Chapter 0. Preface 8
0.1. Who is this book for? 8
0.2. Tasks, games. 8
0.3. Why Visual Basic? 9
0.4. What kind of computer do you need and what version of Visual Basic? 10
0.5. Summary with 10 recommendations
Part I Programming without programming 12
Chapter 1. First steps 13
1.1. What is the program? 13
1.2. Not a program, but a project 14
1.3. First steps - by hand 14
Launch Visual Basic 14
Placing objects on form 15
Writing program 16
Saving, creating, opening, closing a project 17
How to Respond to Visual Basic Error Messages 18
Chapter 2. Project - "Calculator" 20
2.1. Project assignment 20
2.2. Designing 20
2.3. Properties of Forms and Controls 21
2.4. Names and inscriptions 21
2.5. We program. The project is ready 22
2.6. Some other properties of objects 23
2.7. Place the photo on the calculator 24
2.8. Music in project 24
Music in buttons 25
Playing audio CDs 26
Player of your favorite hits 26
2.9. Coordinate system 27
2.10. Message output - MsgBox 28
2.11. User menu 28
2.12. Cinema in project 30
2.13. One last thing you need 30
Comments 30
Move long statement to next line 31
Writing multiple statements on one line 31
Turning our calculator into an independent program 31
How we will further improve our calculator 31
Chapter 3. Working in the Visual Basic Environment 32
3.1. What you need to know and be able to do before sitting down at a computer 32
3.2. Installing Visual Basic 32
3.3. How to work on a project in Visual Basic 33
3.4. Loading and Quitting Visual Basic 33
3.5. Saving the project to disk. Loading a project from disk 33
3.6. Visual Basic 35 Windows
3.7. Visual Basic 36 Main Menu
Toolbar 37
3.8. Transferring your project to other computers 37

Part II. Visual Basic Programming - Level 1 40
Chapter 4. Variables 41
4.1. Variable quantities. Assignment operator 41
4.2. Declaring Variables 43
InputBox 43
Data types 44
Variables and memory 45
What does the assignment operator do to memory 46
Interrupt mode. Step-by-step program execution 46
4.3. More about names 48
4.4. Mathematics. Writing Arithmetic Expressions 48
4.5. Data types and calculation accuracy 50
Integer and Long - integers 50
Single and Double - decimal fractions 50
Whole numbers or decimals? Numeric type Currency 51
Not very outdated ways of declaring variables 51
Formatting result 51
4.6. How to create a simple computing project 52
4.7. String variables 54
4.8. How to display information by the Print 55 operator
4.9. Dialogue with a computer 56
4.10. How to display information in a text field 57
4.11. Let's look around 57
Chapter 5. Branching Programs 58
5.1. What is choice (branching) 58
5.2. Conditional statement If or how a computer makes a choice 58
5.3. Rules for writing a one-line statement If 60
5.4. Random variables 61
5.5. Multiline If 62
5.6. Step recording of program 64
5.7. Nested If statements. Logical operations and expressions 64
Nested If 64 Statements
Logical operations 65
Logical expressions 65
5.8. Select Case 66 Variant Statement
5.9. Improving the calculator. 68
Validating numbers entered into a text field 68
Prohibit division by zero 69
Put a password on the calculator 69
5.10. Function MsgBox 70
Chapter 6. Cyclic programs 72
6.1. GoTo operator. Cycle. Tags 72
Moving objects across the screen 74
6.2. Exiting a Loop with If 74
6.3. Loop statements Do 75
Do operator... Loop 75
Do operator... Loop While 76
Do operator... Loop Until 76
Do While statement... Loop 77
The Do Until… operator. Loop 77
Difference between Do 78 operator options
Operator Exit Do 78
Deprecated loop statement 79
6.4. Operator For loop 79
Exit For 80 operator
6.5. Let's look around 81
Chapter 7. Debugging the program 82
7.1. Types of errors. Error messages. 82
7.2. Debugging the program. Debug windows. Debugging modes. 82
Chapter 8. Typical Small Programs 86
8.1. Computational cyclic program 86
8.2. The role of errors 86
8.3. Counters 87
8.4. Adders 88
8.5. Nesting loops in branches and vice versa 89
8.6. Nested Loops 89
8.7. Finding the maximum of 90 numbers
Chapter 9. Graphics 92
9.1. Objects. Their properties, their events, their methods 92
9.2. Three ways to draw 93
9.3. The first method is Loading ready-made images into Visual Basic 94
Types graphic files 94
Adjusting Image Sizes 94
9.4. Second method - Line and Shape Objects 96
9.5. Mutual overlap of objects. ZOrder 96 method
9.6. Color in Visual Basic 97
9.7. Method 3 - Draw using graphic methods 98
Pset 100 method
Line 100 method
Circle Method 101
CurrentX, CurrentY, Step 101
Method Cls 102
Point 102 method
PaintPicture Method 102
9.8. Using variables in drawing 103
9.9. Using Random Variables in Drawing 105
Chapter 10. Procedures 106
10.1. Why are user procedures needed 106
10.2. Stop, End, and Exit Sub Statements 108
10.3. Variables instead of numbers 110
10.4. Constants 111
10.5. Procedures with parameters 111
Parameter types 113
Chapter 11. Working with timer, time, dates 115
11.1. Data type Date 115
Functions for working with dates and times of day 116
11.2. Timer 117
Loop without loop 117
11.3. Project "Alarm clock-stopwatch" 118
Getting to know the Boolean 121 type
Making an alarm 121
Introducing Enumerated Data Type 124
Timer and simulation 126
11.4. Animation 127
Animation using graphic methods 127
Moving objects 127
“Moving” object properties 128
Cartoon 128
ABOUT transparent color 129
Chapter 12. Using the mouse and keyboard 130
12.1. Using the mouse 130
MouseDown and MouseUp Events 130
MouseMove Event 131
Mouse draws 132
12.2. Using the keyboard 132
KeyDown and KeyUp Events 132
12.3. Project - Racing (game) 133
12.4. Task for the game “Torpedo attack 140”

Part III. Visual Basic Programming - Level 2 141
Chapter 13. Arrays 142
13.1. Variables with indexes 142
13.2. One-dimensional arrays of variables 142
13.3. Two-dimensional arrays 144
13.4. What types of arrays are there 145
13.5. Using Arrays in Game Programming 145
13.6. Arrays of controls 147
Chapter 14. Different animals in one ark 149
14.1. Type Variant 149
14.2. Custom data type 149
14.3. Collections 151
Object variables 151
Collections 152
14.4. Frame 153
Chapter 15. Controls 154
15.1. Checkbox 154
15.2. Switch (OptionButton) 155
15.3. Scrollbars (HScrollBar and VScrollBar) 156
15.4. Slider, ProgressBar 156
15.5. ListBox and ComboBox 157
ListBox 157
ComboBox (drop-down list option) 157
ComboBox ("Simple Combo" option) 158
ComboBox (drop-down Combo option) 158
Properties, events and methods of ListBox and ComboBox controls. 158
15.6. Getting to Know Other Controls 159
MonthView and DTPicker Elements 159
UpDown 160
Elements DriveListBox, DirListBox, FileListBox 160
RichTextBox 161
ListView and TreeView 161
TabStrip and StatusBar 161
MSChart 161
PictureClip 161
ImageCombo 161
MS Comm 161
Chapter 16. Strings, Files, Error Handling 162
16.1. Lines 162
ASCII table 163
16.2. Files 163
16.3. Shell function 167
16.4. Error processing. Statement On Error 167
Chapter 17. Functions. Procedure and Function Parameters 169
17.1. Functions. Function parameters 169
17.2. Local variables 170
Static variables 172
17.3. Arrays as parameters 172
17.4. Passing parameters by reference and by value 173
17.5. Induction. Recursion 173
17.6. Sorting 175
17.7. Objects as procedure parameters 176
Chapter 18. A project that looks solid 178
18.1. What is a Windows 178 application “made of”?
18.2. CommonDialog Control 178
Example of opening and saving files using the Common Dialog element 179
18.3. Toolbar 180
18.4. Project - " Graphics editor" 182
Chapter 19. Projects from several forms and modules 185
19.1. Working with Multiple Forms 185
19.2. Code 186 modules
19.3. Project structure. Project Explorer window. 186
Working with Multiple Modules 186
Working with multiple projects 187
19.4. Visibility zones 187
Variable visibility zones 187
Procedure visibility areas 188
Visibility zones of constants and types 188
19.5. Shading 189
19.6. Name prefixes 190
19.7. Why all this complexity? 190
Chapter 20. User Objects 193
20.1. Encapsulation - "Object in a case" 193
20.2. Game "Net". Problem statement 194
20.3. Timer and general mechanics of the project 195
20.4. Design stage 195
20.5. The order of creating objects 195
20.6. Create a catcher 196
User object - brain without body 196
How to create an object by its class 196
20.7. Let's create a ball. We are completing project 199
20.8. More about objects 202
Form as an object 202
Read-Only Properties 202
Inheritance, polymorphism 203
Chapter 21. Visual Basic and the Internet 204
21.1. Understanding the Internet, Web pages and HTML 204
21.2. Creating a Web Page 204
21.3. Script on Web Page 205
21.4. Access to local disk 207
21.5. Own browser 209
Chapter 22 Visual Basic and Databases 210
22.1. Understanding Databases 210
22.2. Creating a database template using Visual Data Manager 211
22.3. Working with databases. Elements Data management and DBGrid. SQL language. 212
Chapter 23. Goodbye 215
23.1. Unexplored Features of Visual Basic 215
ActiveX 215
Windows API 215
Multi-Document Interface - MDI 215
OLE 215
23.2. A moment between past and future 215
Appendix 1. Necessary information about the computer and the program 218
Chapter 24. First introduction to the computer and the program 219
24.1. What is a computer? First introduction to the program. 219
24.2. How a person communicates with a computer 220
Chapter 25. Program and Programming 221
25.1. List of commands. Command and program modes 221
25.2. What is important to know about the 222 program
25.3. Concept of procedure. Can a robot get smarter? 222
25.4. Computer program in machine language 223
25.5. Programming languages ​​223
25.6. An example of a real computer program in the Logo 225 language
25.7. Sequence of a programmer’s work on a computer 226
25.8. Basic programming techniques 226
Chapter 26. Computer design and operation 229
26.1. How a computer works and works 229
26.2. Device and dimensions random access memory 230
26.3. Interaction of programs in memory 231
26.4. External devices computer 231
26.5. Coding information in a computer 234
Appendix 2. Working in Windows. Entering text 236
Working in Windows 236
Turning your computer on and off. First steps 236
Working with Windows Windows 236
Files and folders 237
File and folder names 238
Explorer 238
Logical drives. File address (path, track to file) 239
How to enter a program into a computer or work with text in text editor 239
Working with one line of text 239
Working with Multiple Rows 241
Code window - a small window on a large sheet with the text 242
Copying, moving, deleting text fragments 242
Magic cancel and back buttons 243
Solving problems 244
References 270
Subject index 272