Introducing Visual Basic

The Microsoft 4GL Development Paradigm

By

Nick Leuci

Los Angeles,  CA

[email-masked]

Copyright  ©  2018  All Rights Reserved

Overview

In 1980, IBM introduced its first generation of ‘personal computer’, the IBM PC, intended as a low-cost entry platform into computing technology for individuals and small businesses.

All computers need an ‘Operating System’, a software system that manages all of the underlying hardware, and provides a logical, simple set of methods to use the system.

IBM chose an obscure startup company in the Seattle area, Microsoft, to implement and license the PC’s operating system.

MS-DOS

The PC was so successful that it is now the dominant platform of computing in most application areas.

The initial MS-DOS operating system was a single-user, command line, character based operating system.  This primitive User Interface still exists in ALL Microsoft operating systems:

Basic

The first MS-DOS programming environment was a BASIC interpreter, developed personally by Bill Gates and Paul Allen.

The BASIC language is a FORTRAN derivative, and it is a statement-based interpreted but procedural language.  Statements are whole logical commands;  the statements are Interpreted (evaluated and decoded) as they are encountered.

Procedural languages contain separate data and command procedures as distinct elements.

ALL IBM PCs, and subsequent clones, were shipped with BASIC installed along with the MS-DOS operating system, and Microsoft continued to support and add new features to it.

A sample BASIC program is on the next slide.

That slide is followed by a slide with a chart showing the evolution of programming languages, including Visual Basic.

Basic Procedure (from ‘.bas’ file)

Sub main()

Dim visApp As Visio.Application  'Visio Application Object

Dim visDoc As Visio.Document     'Visio Document Object

On Error Resume Next

'Get the open instance of Visio

Set visApp = GetObject(, "Visio.Application")

If (visApp Is Nothing) Then

'there is no open instance of Visio, Create one

Set visApp = CreateObject("Visio.Application")

'Add a new blank drawing page

Set visDoc = visApp.Documents.Add("")

Else

'There was an open instance of Visio

If visApp.Documents.Count = 0 Then

'if there are no open documents in this instance of Visio,

'Add a new blank drawing

Set visDoc = visApp.Documents.Add("")

Else

'otherwise, get the currently active document

Set visDoc = visApp.ActiveDocument

End If

End If

'Show a form and put the name of the active document in a text box

Load frmMain

frmMain.Text1.Text = visDoc.Name

frmMain.Show vbModeless

End Sub

Evolution of Programming Languages

1GL    First Generation Languages:  coding directly in machine code (native binary):  11001100011101010110

2GL – Second Generation Languages:  coding in symbolic instruction set Mnemonics for machine Assembler:  MOV DX, AX;  ADD AX, My_Totals;

3GL – Third Generation Languages:  distinct data structures operated on by procedures in a high level compiled language:  if (t.z) ? X = fn(t.z, w*s.y) : X = s.y;

4GL – Fourth Generation Languages:  Objects containing both data and procedures responding to Events and messages:  MyForm.Initialize();  MyForm.Run();

Visual Basic has elements of a 3GL, but it is primarily a 4GL Programming Language for Microsoft Windows.

MS Window GUI

Many companies and people made a huge R&D effort into developing operating systems that had a Graphical User Interface, or “GUI”.  A GUI has visual, graphical elements for users to manipulate, instead of entering command line text commands.

Microsoft first introduced a GUI in the 1980s, MS Windows versions 1.x and 2.x.  These were not successful for many reasons:

¨     The hardware was not yet powerful enough to run the GUI environments efficiently;

¨     There were design problems in the operating systems;

¨     A lack of applications that took advantage of GUIs.

MS Window 3.x and Visual Basic

In the early 1990s, after there were significant advances in hardware capability, Microsoft introduced MS Windows Version 3, which was a huge success.

MS Windows 3 was a true GUI environment, and a precursor to all later Windows GUIs;  they share these graphical (image-based) features:

¨     Desktop

¨     File system navigator (Windows Explorer)

¨     Applications in Client Windows with ‘widget’ controls

¨     Icons

¨     Menus / submenus

¨     Dialog boxes

Visual Basic

At first, Windows applications were built with procedural, character based programming tools.  It was clumsy and awkward to build GUI applications with a procedural development language.

Microsoft and others started building development environments that ran in a GUI to develop for the GUI.  One of the earliest and most successful GUI languages was Visual Basic, developed by Alan Cooper.

Alan Cooper did not try to market and distribute his tool himself.  Instead, he negotiated a deal with Microsoft, to sell Visual Basic and all rights to it.  Microsoft issued VB 1, and has continued to invest in its improvement.

The next slides present an informal, brief history of programming languages.

A Very Brief History of OOP Languages

|

Visual Basic Programming

Visual Basic (VB) is a Rapid Application Development (RAD) tool that supports visual programming by means of mouse-controlled ‘point and click’ with ‘drag and drop’.

Visual Basic is used to build MS Windows GUI applications only.

VB can NOT build character-based applications for MS-DOS.

VB can NOT build applications for other operating systems, for example Linux.

Visual Basic 6 can be used to build applications for these MS Windows platforms:

Windows  95,  98,  NT 4 Server,  NT 4 Client,  2000 Pro,  2000 Me,  and  XP.

Visual Basic Programming Elements

All Visual Basic programs consist of some combination of these essential and required elements:

¨     Controls:  the ‘widgets’ a program does work with

¨     Properties:  the settings and attributes unique for each control

¨     Events:  activations that a control responds to, or sends to another control;  each activation is associated with an underlying MS Windows ‘message’

¨     Methods:  standard (built-in) and programmer-defined procedures to operate on controls and respond to events

¨     Forms:  the visual containers that bind and connect all of the elements together into a cohesive program

Visual Basic Forms

The main ‘form’ is the container which holds the context for a Visual Basic application.  When the main form is loaded, program initialization takes places, and the forms controls and event-processing are active.

Visual Basic:  Event-Driven Programs

A Visual Basic form has menus and controls that allow users to operate the program:

These controls can originate or receive “Events”; Visual Basic Programming is called ‘Event-Driven Programming’.

Visual Basic Events

Visual Basic Events are internal Windows messages sent when the user of the program makes something happen by clicking the mouse on a control, menu, etc.  Pressing control keys, and other running processes, can also generate events.

Pressing the ‘Do 5 Picks’ button causes the main form to generate a number display, as shown here:

Visual Basic Properties and Methods

All forms and controls have ‘properties’, a set of attributes unique to the widget, and each of these attributes can have values that can be changed, affecting the display and behavior of the widget.  This ‘About’ Dialog Box has text controls with different color attribute settings.

Methods are Visual Basic procedures that are available for a widget.  This Dialog Box has a “Show()” method to make it visible.

Visual Basic Programming Projects

When VB is started, a dialog box asks the programmer to pick a new project, or to work on a recent or existing project.  A project consists of a group of files that together make up the application.

Visual Basic Programming Forms

The main form is the default form every VB application starts with.  The programmer can resize it, rename it, add controls, set properties, use methods, and handle events for it.

Visual Basic Programming Controls

Controls are added to a form by using the toolbar that contains the current set of controls.  Each control is a widget with interesting features:  command buttons, edit windows, text boxes, labels, etc.

Visual Basic comes with a standard set of controls, but a programmer can use others from VB, or made by non-Microsoft vendors specifically for VB.  To get a control, point and click, then drag and drop the control onto the form.

Visual Basic Form / Control Properties

VB forms and controls have an associated property sheet, where the programmer can pick a specific property and change its setting:

Visual Basic Programming Event Editor

In VB, the programmer can pick specific events for a form or control, and write a method to handle what happens when that event occurs.  Below is the ‘click event method’ for a command button:

Visual Basic Programming Run:Compile

VB programming consists of creating forms, adding controls to the forms, setting the properties of the forms and controls, and writing methods that handle specific GUI events or enhance the behavior of the forms and controls.

When this development activity is ready to be tested, the programmer uses VB’s menus or icon buttons to run the program with a full compile.  The example below shows using the VB “Run:Compile” menu command.  Note the accelerator key (Ctrl+F5), an alternative way to accomplish the same thing.

Visual Basic Programming Build ‘Exe’

When a VB program is ‘run’, it is interpreted inside of VB itself.  To make a Windows application, the programmer must create an executable program image (‘.exe’ file), as shown here:

Visual Basic Programming Save

It is essential for the programmer to ‘save’ project development work regularly, so the work and time involved won’t be lost:

Visual Basic Programming Project Files

VB programming involves work on multiple files, all conveniently stored in the application’s ‘project directory’.  The project itself has ‘.vbp’ and ‘.vbw’ extensions, the forms have ‘.frm’ and ‘.frx’ extensions, and source code modules have the ‘.bas’ extension.