Category Archives: Visual Basic

What are the Uses of Visual Basic?

You may have heard that Visual Basic is evolved from the DOS version of BASIC, which means it is the beginners’ all-purpose symbolic instruction code. Being the third-generation event-driven programming language, Visual Basic was released by Microsoft in 1991. VB was considered as one of the most powerful programming languages ever existed then, and it would enable anyone including beginners to easily develop GUI window applications. As compared to other computer programming languages, such as C, C++, Visual Basic is user-friendly and easy to learn and understand. The only thing you need to have in order to learn this language is dedication and determination.

Since the primary release of VB, Microsoft released many versions of Visual Basic, from Visual Basic 1.0 to the ultimate version Visual Basic 6.0. All of these versions were effectively used by the VB developers. The VB programming language allows programmers to make software interface and codes in a simple to use graphical environment.

Uses of Visual Basic

Visual Basic for Applications allows users to perform a myriad of functions that go beyond simple word processing and spreadsheet functions. For the typical user, VBA helps to make frequent everyday tasks less repetitive via macros. While, macros can be used to automate repetitive word, data-processing functions, generate custom forms, graphs, and reports. There are plenty of other uses which can be done using Visual Basic and they are:

1.     Creating Software Interface and Codes

A visual basic programming language allows programmers to create software interface and codes in an easy to use graphical environment.

2.     Creating forms having specific attributes

VB is a combination of different components with the help of which it is used to create forms having specific attributes and actions. A programmer can create a number of applications using the components provided by the Visual Basic program.

3.     Developing Window based Applications

VB allows programmers to develop widows based applications rapidly. Programs written in Visual Basic can also use the Windows API, which requires external function declarations.

4.     Accessing databases

Visual Basic greatly helps in accessing databases using ADO which will let programmers use ActiveX controls and various objects.

5.      Developing games

While Visual Basic is intended more to develop applications, it is also useful for games development for particular or limited purposes, unlike C++ that is more suitable for developing games.

How is Visual Basic Applications used?

  • VB Applications are used within MS Office applications to automates tasks like generating customized charts and reports, perform word and data-processing functions.

For example, with a single click, you can create an entire balance sheet from a series of accounting entries in a spreadsheet.

  • Computer professionals or programmers use macros in replicating large pieces of code, designing specific languages and merging existing program functions.
  • Many professional companies and organizations use Visual Basic Applications in non-Microsoft settings by using a technology called “COM interface”. It will allow these companies/organizations to interact across computer boundaries. Many firms have implemented VBA within their own applications, both proprietary and commercial, including Corel, SolidWorks, AutoCAD, CATIA, raw, and ArcGIS.


Compared to other languages Visual Basic could be slower, yet it is flexible and easier. Since it is one of the popular programming languages, many related books and other resources are available. This is helpful if you’re interested to learn more about Visual Basic language. Taking Visual Basic Training could also help you to conveniently develop programming skills and understand that learning Visual Basic programming language is the right choice for your career growth.

Once you have your VB skills developed move onto other languages like VB script. However, all this depends on your interest and desire. Also, keep in mind, Visual Basic is one of the most important programming languages having a powerful front-end tool.  These powerful front-end tools will help you to achieve simple and complex business requisites in an effective and efficient manner.

Crystal Reports and Visual Basic 6.0

Reports can be made quickly and easy for use with VB with Crystal Reports. But there are some problems you can encounter. For example if you use ODBC the name of the used DSN connection is saved within the report. Also when your users want to change the layout of the report they need a direct connection to the database. You can use views or a special user account to protect the structure of your database.


An other way is to make use of Data Definition files. They are just ASCII files which contains the fields and their properties that are to be used in the report. Using such a file means that there is no direct connection with the database. In Visual Basic the query is executed and the result – together with the Data Definition file – will produce the report.

To make it work you have to take three steps:


  • making the Data Definition file
  • making the report
  • merge them in VB and show the result


The Biblio.mdb will be used in this example.


Step 1: making the Data Definition file


The report needs to be a view to be of all present authors with their titles and year of publication. The fields Author.Author, Titles.Tiltle and Titles.Year Published must be shown on the report. Due the keys the table Title Authors is used. The SQL to get the result is:


SELECT Authors.Author, Titles.Title, Titles.[Year Published]

FROM Titles INNER JOIN (Authors INNER JOIN [Title Author] ON Authors.Au_ID = [Title Author].Au_ID) ON Titles.ISBN = [Title Author].ISBN;


Making the Data Definition file can be done in Crystal Reports but also in any ordinary editor like notepad. The format is fixed:







All on one line separated by a TAB.


Author   String   255 name

Title    String   255 Title

YearPublished    String   4   year


Don’t forget to save the file with the name: AuthorTitles.ttx Crystal Reports needs that to be able to define a report on this file.


Step 2: making the report


Start Crystal Report; choose for New, Standard report. On the tab Data select Active Data. On the next screen the choice is Data definition. Select with Browse the file you have made in step 1. Click on Finish. On the tab Fields select Add all and then  Preview Report.

The report will be shown. As values the given descriptions will be shown. With Design you can change what you want on the report. Just save the report (standard extension .rpt). For quick merging in VB use the same name for the report as for the Data Definition file: AuthorTitles.rpt


Step 3: merge them in VB and show the result


Open a new project in VB (name = prjDDCR). Place on the default form (name = frmDDCR) a commandbutton (name = cmdShowReport; caption = Show report). Don’t forget to add the reference for DAO (Microsoft DAO Object Library ) and for Crystal Reports (Crystal Reports Engine Object Library).


Add the next code to the general section of the form. (It’s just an example so all values are hard-coded.)


Option Explicit


Private db              As DAO.Database

Private CDOSet          As Object

Private RepApp          As Object

Private CrystRep        As CRPEAuto.Report

Private RepDb           As CRPEAuto.Database

Private RepTables       As CRPEAuto.DatabaseTables

Private RepTable        As CRPEAuto.DatabaseTable

Private LabelRows()     As Variant


On the Form_Load event add the next code. Don’t forget the code in the Form_Unload event! Change the path to the right location of your local Biblio.mdb


Private Sub Form_Load()

Set db = OpenDatabase(App.Path & “\biblio.mdb”)

End Sub


Private Sub Form_Unload(Cancel As Integer)



End Sub


Under the cmdShowReport_Click event is the code which merge the result of the executed SQL with the Data Definition file and the actual report.


Private Sub cmdShowReport_Click()

Dim strSQL          As String

Dim rs              As DAO.Recordset

Dim intFN           As Integer

Dim strFN           As String

Dim strLine         As String

Dim intX            As Integer

Dim intC            As Integer

Dim intLabelCount   As Integer

Set RepApp = CreateObject(“Crystal.CRPE.Application”)

Set CrystRep = RepApp.OpenReport(App.Path & “\AuthorTitles.rpt”)

Set CDOSet = CreateObject(“CrystalDataObject.CrystalComObject”)

intLabelCount = 0

intFN = FreeFile

strFN = App.Path & “\AuthorTitles.ttx”

Open strFN For Input As intFN

Do While Not EOF(intFN)

Line Input #intFN, strLine

If Len(strLine) <> 0 And Right(strLine, 2) <> “%%” Then

CDOSet.AddField Split(strLine, vbTab)(0), vbString

intLabelCount = intLabelCount + 1

End If


strSQL = “SELECT Authors.Author, Titles.Title, Titles.[Year Published]” + _

” FROM Titles INNER JOIN (Authors INNER JOIN [Title Author] ON ” + _

” Authors.Au_ID = [Title Author].Au_ID) ON Titles.ISBN = [Title Author].ISBN;”

Set rs = db.OpenRecordset(strSQL)

With rs

If Not (.EOF And .BOF) Then


ReDim LabelRows(.RecordCount – 1, intLabelCount – 1)


For intX = LBound(LabelRows) To UBound(LabelRows)

For intC = 0 To .Fields.Count – 1

LabelRows(intX, intC) = CStr(“” & .Fields(intC).Value)

Next ‘intC


Next ‘intX

CDOSet.AddRows LabelRows

Set RepDb = CrystRep.Database

Set RepTables = RepDb.Tables

Set RepTable = RepTables(1)

Call RepTable.SetPrivateData(3, CDOSet)

CrystRep.Preview “AuthorTitles.rpt”


End If

End With

Set rs = Nothing

Set RepApp = Nothing

Set CrystRep = Nothing

Set CDOSet = Nothing

End Sub


Compile the project. Just hit the command button. Crystal Reports will open a separate window to show the result of the executed query in the report. You can open as much reports as you wish.

The advantage of using a Data Definition file is that no difficult solutions has to be made on the database side. You don’t have to make views available to the users. You don’t have to make a special user with only access to those tables you want. Adding a new report does not mean to be forced to compile a new executable. If you save the SQL and the Data Definition files in the database you only have to update the relevant tables. You can save the reports also in the database but it’s better to have them located outside the database. Showing all available reports form a certain location is just easy to do. Merging the three files together is just a simple extension on the example project.