contents   index   previous   next



Tutorial: Creating GUI for your Fortran programs using Visual Basic and f90VB

 

 

Copyright © 2000 Canaima Software, Inc.

 

 

Most of the examples in the f90VB User Manual are short programs intended to show you the most basic way of using the components included in the f90VB libraries. This example is a little more complex; it shows you what could be considered a real-case scenario. We’ll build a fully functional Fortran program with a nice GUI created in Visual Basic. The GUI elements feature menus, several dialog boxes (some with data entry), a grid control and events. Throughout the example we also explain several interface techniques that can be used in your own Fortran-VB projects.

 

Our main window is a VB form that looks like Figure 1.

 

There is a menu bar on top, with three main entries: File, Tools and About. The only sub-menu option for Files is Exit, which closes the application. The About menu also has only one sub-menu option, About f90VB Demo, which displays a standard About Dialog Box (Figure 2).

 

As shown in Figure 3, the Tools menu entry presents the user with three sub-menu options. The first two options, Logs Table and Factorials Table compute a table of logarithms or factorials respectively. The table is shown in the grid below the menu bar, which is a standard MSFlexGrid. The third option (Excel Chart) will create an Excel spreadsheet with a chart which plots the values in the MSFlexGrid.

 

The GUI also includes two additional dialog boxes. The first is an input box which allows the user to supply the upper value for the logarithms or factorials table (the initial value is always one). So when any of these two tasks is selected, a dialog box will pop up asking for this value (Figure 4). As you can see, the dialog box has an option to cancel the calculation if desired. The second is a dialog box to display any errors that may occur during the program execution (Figure 5).

 

These are all the elements of our project’s GUI and a general description of what they do. These forms can be created fairly easily using Visual Basic and, of course, we will want to use Fortran to build the main program to drive all these GUI elements. The only problem is that Visual Basic forms cannot be exposed publicly because they only work inside Visual Basic applications. Because of this, you cannot access them directly using f90VB’s Automation library. So we need to make these forms accessible from Fortran-f90VB by wrapping them with ActiveX objects. Let’s see how this is done.


Creating an ActiveX DLL with Visual Basic

Creating the CError ActiveX component

Creating the CAbout ActiveX component

Creating the CInput ActiveX component

Creating the CMain ActiveX component

Converting your Visual Basic Project into an ActiveX EXE

Writing a test main Fortran application

Writing the real event handler for CMain

Getting rid of that ugly Console Window

Conclusions

For more information and other articles

Disclaimers and other legal issues