Visual Basic Concepts

Source: Internet
Author: User
Tags execution

To understand the application development process, first understand some of the key concepts that Visual Basic relies on to create. Because Visual Basic is a Windows development language, it is necessary to maintain a certain similarity to the Windows environment. If you are unfamiliar with Windows programming, you need to understand some of the fundamental differences between programming in a Windows environment and programming in other environments.

How Windows Works: Windows, events, and messages

A comprehensive discussion of the internal working mechanism of Windows will require a full volume of the book. There is no need to get into all the technical details. The working mechanism of Windows is simply three key concepts: windows, events, and messages.

Simply consider a window as a rectangular area with boundaries. You may already know several different types of Windows: For example, the Windows 95 Explorer window, the document window in a word processor, or a dialog box that prompts for appointment information. In addition to these most common windows, there are actually many other types of Windows. A command button is a window. icons, text boxes, option buttons, and menu bars are also windows.

The Microsoft Windows operating system manages all windows by assigning a unique identification number (window handle or hWnd) to each window. The operating system continuously monitors the signal of the activity or event of each window. Events can be generated by actions such as clicking a mouse or pressing a key, or by controlling the program, or even by the operation of another window.

Every time an event occurs, a message is raised to the operating system. The operating system processes the message and broadcasts it to other windows. Each window can then take the appropriate action based on its own instructions for handling the message (for example, when the window is removed from the other window, it will display its own window).

As you can imagine, all the possible combinations of Windows, events, and messages will have an amazing amount of work to do. Fortunately, Visual Basic lets you get rid of all low-level message processing. Many messages are automatically processed by Visual Basic, and others are handled by the programmer as an event procedure. This allows you to quickly create powerful applications without needing to deal with unnecessary details.

Event-driven model

In traditional or "procedural" applications, the application itself controls which part of the code is executed and in what order. Executes the program from the first line of code and executes it according to a predetermined path in the application, calling the procedure if necessary.

In an event-driven application, the code does not execute according to a predetermined path, but instead executes different pieces of code in response to different events. Events can be triggered by user actions, or by messages from the operating system or other applications, or even by messages from the application itself. The order of these events determines the order in which the code executes, so the path of the code that the application passes each time it runs is different.

Because the order of events is unpredictable, you must make certain assumptions about the "various states" of execution in your code. When making certain assumptions (for example, suppose that the input field must contain a certain value before it is run to process an input field, the structure of the application should be organized to ensure that the assumption is always valid (for example, to prohibit the use of command buttons that start the process before a value is available in the input field).

The code can also trigger events in execution. For example, changing the text in a text box in a program raises the change event for the text box. If the Change event contains code, it will result in execution of the code. If you originally assumed that the event could only be triggered by user interaction, you might have unexpected results. For this reason, it is important to understand the event-driven model and keep it in mind when designing an application.

Interactive development

The traditional application development process can be divided into three distinct steps: coding, compiling, and testing the code. However, unlike traditional languages, Visual Basic uses an interactive approach to develop applications that no longer have significant boundaries between the three steps.

In most languages, if an error occurs while writing code, the error is captured by the compiler when the application starts to compile. You must find and correct the error at this point, and then compile again, repeating the process for each found error. Visual Basic interprets the programmer as it enters the code, capturing and highlighting most of the syntax or spelling errors immediately. Looks like an expert in monitoring code input.

In addition to instant catch errors, Visual Basic compiles the code partially when it is entered. When you are ready to run and test your application, it takes a very short time to complete the compilation. If the compiler finds an error, the error is highlighted in the code. You can correct the error and continue compiling without starting from scratch.

Because of the interactive nature of Visual Basic, you can find that you are running your application frequently when you develop your application. In this way, the effect of code runs can be tested at development time without having to wait until the compilation is complete.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.