Introduction to Visual Basic – Chapter 2 – Visual Basic

Chapter 2

Introduction to Visual Basic



  1. What is Visual Basic?
  2. Structure of Visual Basic Application
  3. The state of Visual Basic Application


What is Visual Basic?

Visual Basic is a Visual programming tool that allows you to develop Windows (Graphic User Interface – GUI) applications.  These applications have a familiar appearance to the user thus, are easy to use.

Visual Basic is event-driven programming, meaning code remains idle until called upon to respond to some event (button click, menu selection, keypress, Lost_Focus and so on).  Visual Basic is governed by an event processor.  Nothing happens until an event is detected. Event is made or triggered by the user. Once an event is detected, the code corresponding to that event (event procedure) is executed.  Program control is then returned to the event processor.


Event Processor

Block Diagram of Event Processor

Figure 1 Block Diagram of Event Driven Programming


Structure of a Visual Basic Application


Structure of a Visual Basic Application

Structure of a Visual Basic Application

Figure 2 Structure of Visual Basic Application


Visual Basic Application is made up with collaboration of these components:


  1. Forms – Forms are the Windows that you create for user interface for application. Besides standard forms, Visual Basic also supports Multiple Document Interface (MDI) forms, as well as a whole number of predefined forms.
  2. Controls – Controls are the inbuilt graphical features drawn on forms to allow user interaction. These controls are provided by Visual Basic, and can be drawn by dragging from tool box. Text boxes, labels, scroll bars, command buttons, etc. are examples of controls. The control hidden in tool box can be added by adding components. (Project > Components)  (Forms and Controls are objects.)
  3. Properties – Every characteristic of a form or control is specified by a property.  Example properties include names, captions, size, color, position, and contents.  Visual Basic applies default properties.  You can change properties at design time or run time.
  4. Methods – Methods are built-in procedure that can be invoked to impart some action to a particular object. Show, Hide, Move, Load, Unload, etc are some methods used in Visual Basic 6.
  5. Event Procedures – Event procedures are code related to some object.  This is the code that is executed when a certain event occurs. Code written under the Click event of the Command1 button is the event procedure that will be executed when the button is clicked.
  6. General Procedures – General procedures are code not related to objects.  This code is written by programmer to eliminate the writing of mostly occurring group of statements or functions. This code is executed when called by the application.
  7. Modules – Modules are collections of code and data that function something like objects in Object-Oriented programming (OOP), but without defining OOP characteristics like inheritance, polymorphism, and so on. The point behind modules is to enclose procedure and data in a way that hides them from the rest of the program. A module also contains general procedures, variable declarations, and constant definitions used by application.


The State of Visual Basic Application

Visual Basic application can be viewed in three distinct states: design, execution, and break.


In the design state, you can edit the user interface or attach codes to the application. In this state, programmer uses there longest time available for project. All the windows of the IDE and its components are available to you. Design state is composed of three steps:

  1. Draw the user interface.
  2. Assign Properties to the controls.
  3. Attaching code to the controls.


In the execution state, the application is running. Only a few commands are available, and none of the windows of IDE are available. You can neither edit the user interface nor add code to an application while it’s running. This state is also called run state. This state is some what like testing state of the application, errors in application can be known by this state but debugging activities are not included in this state.


In the break state, the application’s execution has been interrupted temporarily and can resume when you press F5 or choose Run > Continue. The immediate window is activated, and you can edit the code and issue commands in it. However, you can’t edit the user interface. So, in this state testing and debugging of the application is done at same time by breaking the application.