Visual Basic Concept
To understand the application development process, you must 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 with the Windows environment. If you are not familiar with Windows programming, you need to understand some fundamental differences between programming in Windows environment and programming in other environments.
How Windows works: windows, events, and messages
A comprehensive discussion of Windows' internal working mechanisms will require the capacity of a whole book. There is no need to dig deep into all the technical details. The working mechanism of Windows is simply called three key concepts: windows, events and messages.
You might as well think of the window as a rectangular area with boundaries. You may have learned about several different types of windows: for example, the Explorer window of Windows 95, the document window in the word processor, or a dialog box that pops up with date information. In addition to these most common windows, there are actually many other types of windows. The 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 signals of activities or events of each window. Events can be generated by operations such as clicking the mouse or pressing a key, or by controlling the program, or even by the operation of another window.
Each event occurs, a message will be triggered to send to the operating system. The operating system processes the message and broadcasts it to other windows. Each window can then take appropriate actions based on its own instructions to process the message (for example, redisplay its own window when the window uncovers other windows).
It is conceivable that there will be an amazing amount of work to handle all possible combinations of windows, events, and messages. Fortunately, VisualBasic gets you out of all the low-level message processing. Many messages are automatically processed by Visual Basic, and others are processed by the programmer as event processes. This allows you to quickly create powerful applications without dealing with unnecessary details.
Event-driven model
In traditional or "process" applications, the application itself controls which part of the code is executed and in what order. Execute the program from the first line of code and execute it in the predetermined path in the application, calling the process if necessary.
In event-driven applications, the code is not executed in a predetermined path, but executes different code snippets in response to different events. Events can be triggered by user operations, or messages from the operating system or other applications, or even messages from the application itself. The order of these events determines the order in which code is executed, so the path to the code that the application passes through each time it runs is different.
Because the order of events is unpredictable, certain assumptions must be made in the code about the "various states" when executed. When certain assumptions are made (for example, assuming that the input field must contain a determined value before running a process to process an input field), the application structure should be organized to ensure that the assumption is always valid (for example, the command button that initiates the process is prohibited before there is a value in the input field).
The code can also trigger events during execution. For example, changing the text in a text box in a program will raise the Change event of the text box. If the Change event contains code, it will result in execution of that code. If it turns out that the event can only be triggered by user interaction, unexpected results may be produced. Because of this, it is very important to understand event-driven models when designing applications and keep them in mind.
Interactive development
The traditional application development process can be divided into three obvious steps: encoding, compiling and testing code. But Visual Basic is different from traditional languages, using interactive methods to develop applications, leaving no clear boundaries between the three steps.
In most languages, if an error occurs while writing the code, the error is caught by the compiler when you start compiling the application. At this time, the error must be found and corrected, and then compiled again. This process must be repeated for each error found. VisualBasic interprets as programmers enter code, instantly capturing and highlighting most syntax or spelling errors. It looks like an expert is monitoring the input of the code.
In addition to instantly catching errors, VisualBasic also partially compiles the code when entering it. Compilation takes only a very short time when preparing to run and test the application. If the compiler finds an error, the error is highlighted in the code. This time you can correct the error and continue to compile without starting from scratch.
Due to the interactive nature of Visual Basic, you can find that you are running your application frequently when you are developing it. In this way, the effect of code running can be tested during development without having to wait until the compilation is completed.