Dec 102017
Self-extracting text file (MS Word) describing how to link Visual Basic 3 and MS Fortran 5.1.
File HF1047.ZIP from The Programmer’s Corner in
Category Recently Uploaded Files
Self-extracting text file (MS Word) describing how to link Visual Basic 3 and MS Fortran 5.1.
File Name File Size Zip Size Zip Type
HF1047.DOC 173568 15253 deflated
TPCREAD.ME 199 165 deflated

Download File HF1047.ZIP Here

Contents of the HF1047.DOC file


!"#$%&'()*+,-./0123456789:;<=>[email protected][\]^_`abcdefghijklmnopqrstuwxyz{|}~Root [email protected]

FMicrosoft Word 6.0 Document
DhC:\WORD\TEMPLATE\APPNOTE.DOTMicrosoft CorporationSuzanne [email protected]%[email protected]'ze-eS'#[email protected](q\W0

[email protected] AppnoteTitle "Enter the title of the appnote."Using FORTRAN 5.1 with Visual Basic
ask Product "Enter the product name."FORTRAN
ask version "Enter the current product version."5.1
ask authr "Enter the author's name."Rich Clay
ask contents "If there is no disk, type No. If there is a disk, type 1 (or the appropriate number)"No
ask appnumber "Enter the appnote number."HF1047
ask creationdate "Enter the creation date."6/1/94
ask copyrightdate "Enter the copyright date(s)."1994
ask modifydate "Enter the current month/year (e.g., 7/90)."9/94

Application Note History
For Internal Use Only

AppNote Number:appnumber \*charformatHF1047
Title:AppnoteTitle \*charformatUsing FORTRAN 5.1 with Visual Basic
Product:Product \*charformatFORTRAN
Versions:version \*charformat5.1
Original Author:authr \*charformatRich Clay
Creation Date:creationdate \*charformat6/1/94

Revision DateChanges by/ Comments8/18/94Edited; Stu Klingman9/19/94Revised; Stu Klingman9/20/942nd Edit; Kay Dayss9/21/94Author review; Rich Clay9/23/94Proof/Finalization -- SuzanneM
Microsoft Product \* charformatFORTRANVersions:Version \* charformat5.1Product Support ServicesSubject:AppnoteTitle \* charformatUsing FORTRAN 5.1 with Visual BasicApplication NoteContents:5 if =(numpages6 - 1)5 = 1 "Page, " "Pages, "Pages, contents \* charformatNo Diskmodifydate \* charformat9/94 SYMBOL 45 \f "Symbol" AppNumber \* charformatHF1047
INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY ACCOMPANY THIS DOCUMENT (collectively referred to as an Application Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. The user assumes the entire risk as to the accuracy and the use of this Application Note. This Application Note may be copied and distributed subject to the following conditions: 1) All text must be copied without modification and all pages must be included; 2) If software is included, all files on the disk(s) must be copied without modification (the MS-DOS utility diskcopy is appropriate for this purpose); 3) All components of this Application Note must be distributed together; and 4) This Application Note may not be distributed for profit. Copyright copyrightdate \*charformat1994 Microsoft Corporation. All Rights Reserved.Visual Basic, Microsoft, and MS-DOS are registered trademarks and Windows is a trademark of Microsoft Corporation.This document was created using Microsoft Word for Windows.

FORTRAN and Visual Basic for Windows

There are several points to consider when using FORTRAN from Visual Basic:

Calling FORTRAN routines from Visual Basic for Windows requires that the FORTRAN routine be made into a DLL.

When passing data:

Both FORTRAN and Visual Basic pass data by reference
Visual Basic strings are different from FORTRAN strings, and include a string structure. They require a special declaration (ByVal) which forces Visual Basic to pass the string pointer
In Visual Basic array indices start at 0, and in FORTRAN they start at 1.

There must be a declaration statement in Visual Basic for each FORTRAN routine which will be called.

FORTRAN DLLs have 2 significant problems in file I/O:

Unformatted or Binary files cant be accessed with FORTRAN commands.
ASCII files that are opened in FORTRAN will not be readable until you exit from Visual Basic.

The solution to both problems is to use Windows API calls to do file I/O.

NOTE: For additional information on file I/O, please see the following article in the Microsoft Knowledge Base:

Title:INF: Performing File I/O from a FORTRAN Dynamic-Link Library

Creating a FORTRAN DLL Called from a Visual Basic Program

This lab presents the steps required to build a FORTRAN DLL and shows how to create a Visual Basic application which uses this DLL. This lab also shows the syntax required to pass various types of data between FORTRAN and Visual Basic.

1.Install FORTRAN version 5.1 to target MS-DOS and Windows and include the Windows DLL library. When this is completed successfully, the files \FORTRAN\BINB\FL.DEF and \FORTRAN\LIB\LDLLFEW.LIB will have been put onto your PC.

NOTE: If there are problems with any of this, please use the additional information provided in the following article in the Microsoft Knowledge Base:

Title:INF: FORTRAN 5.1 Setup Procedure for Typical Installations

2.Install Visual Basic version 3.0.

3.Read chapters 1 & 2 of the Visual Basic Programmers Guide, and do the Hello World example.


1.Start Visual Basic and begin a new project.

2.Add the following items to the Form by dragging them from the Tool Box to the Form:

4 Command Buttons
1 Text Box

3.In the Properties Window, modify the properties of the following items:

ObjectPropertiesSettingForm CaptionVB/Fortran LabText BoxText
Multi Line
Scroll Barsempty
3 BothCommand Button 1 CaptionTest ArrayCommand Button 2CaptionTest StringCommand Button 3 CaptionTest String ArrayCommand Button 4 CaptionTest Square
At this point the Form should look something like this:

4.From the Project Window, select View Code for the Form.

5.Add the Visual Basic code as follows.

In the following sections, add the code indicated by the symbol (:

Add the following code to the Command1 Click event:

Sub Command1_Click ()
( Static arr(1 To 3, 1 To 7) As Single
( Call ARRAYTEST(arr(1, 1))
( For i% = 1 To 3
( For j% = 1 To 7
( text1.Text = Str$(arr(i%, j%)) + Chr$(13) + Chr$(10) + text1.Text
( Next j%
( Next i%
End Sub

Add the following code to the Command2 Click event:

Sub Command2_Click ()
( Dim temp As String * 40
( Call STRINGER(temp)
( text1.Text = temp + Chr$(13) + Chr$(10) + text1.Text
End Sub

Add the following code to the Command3 Click event:

Sub Command3_Click ()
( Static testarray(1 To 5) As StringArray
( Call ARRAYSTRING(testarray(1))
( For i% = 1 To 5
( text1.Text = testarray(i%).strings + Chr$(13) + Chr$(10) + text1.Text
( Next i%
End Sub

Add the following code to the Command4 Click event:

Sub Command4_Click ()
( Dim a As Single
( a = 4.2
( Call Square(a)
( text1.Text = Str$(a) + Chr$(13) + Chr$(10) + text1.Text
End Sub

6.Create the files for the form by choosing "Save Project As" from the file menu. In a directory of your choice, save the form as VBFORT.FRM and save the project as VBFORT.MAK. Create a new module, and save it as GLOBAL.BAS

7.From the Project Window select View Code for GLOBAL.BAS. Add all of the following code to general declarations section in GLOBAL.BAS:

Type StringArray
strings As String * 24
End Type

Declare Sub ARRAYTEST Lib "fortvb.dll" (Myarray As Single)
Declare Sub STRINGER Lib "fortvb.dll" (ByVal mystring As String)
Declare Sub ARRAYSTRING Lib "fortvb.dll" (Myarray As StringArray)
Declare Sub Square Lib "fortvb.dll" (a As Single)
Note: The DLL name in these declarations could include full path to the FORTRAN DLL so that Visual Basic doesnt have to search for it. For example: "C:\VB\TEXT\FORTVB.DLL".

8.Create the FORTRAN file to be made into a DLL as follows:

Create a file (FORTVB.FOR) with the following contents and place it in the same directory where the Form and other Visual Basic files are located:

subroutine arraystring(arr)
character*24 arr(5)
arr = 'This is a string also'

subroutine arraytest(arr)
real*4 arr(3,7)
integer i,j
do i=1,3
do j=1,7
arr(i,j) = 11*i+j-1*i
end do
end do

subroutine square(a)
real*4 a
a = a*a

subroutine stringer(s)
character*40 s
s = 'This is from fortran'

9.Create the Definitions file as follows:

Create the file FORTVB.DEF with the following contents:



10.Build the DLL by typing the following commands at the MS-DOS prompt in the same directory as above:

FL /c /Gw /Aw /G2 FORTVB.FOR
11.Copy the DLL to a directory where Visual Basic can find it if the declarations did not include the full path to the DLL. This would be either the working directory, the directory C:\WINDOWS\SYSTEM, or a directory in the path.

Note: loading a Visual Basic project does not change the working directory. The current project directory is not usually searched when loading a DLL.

12.Run the Visual Basic application, and click the command buttons to execute the FORTRAN subroutines. The results will appear in the text window.

appnotetitle \*charformatUsing FORTRAN 5.1 with Visual BasicPage page2

Microsoft Product Support Services

Microsoft Product Support Services

dD^"$Dxxl$NPPb$x}yvtszrpqfq\rRsHt>v4x*y }",[email protected]^hr| *4>HR\fpz|zrmh^[email protected],"-n$5}{yupkf\RHC>94/*(!
",[email protected]^hm r*v4w>tDpHmOhReX^\W^[email protected],u"wy{}Jd-D$ `@Bxx{xvttvvtrl"i,e6$x}yvtsrqxqnrdsZtPvFx
",[email protected]^hr|
(2-n$5}xndZUPKFA<:3.-($"",[email protected] T"^&h,m2r$T,T-&$\]\[YXSND:2&zxvtrqponnpru|xr{h}^[email protected])$! "$*16<"@%J+T1^6h8r;|>BRUY^chrw|||rtmhl^pTT|",[email protected]^hr%.9?F|JrNhQ^[email protected],I"[email protected]:5&$x|zp}fy\vRtHs>r4q*q rstvxy}|voljfb]ZWV"T,[email protected]^[h]rb|hlsv *4>HR\`fnpz|zrmh^[email protected],"-n$5A?=94/* ",[email protected]^hmrvwtpmhe^ W"T(J*[email protected],9";[email protected]$KF<6$-*(.&8BLV`jtTUVY_dx2<

```(+9%I;/]E:IS+l!!YQjGg2a1a{ SgC..Y&FQI.hRj#SJjl3uAJe7,,NQ dVoCYr63_wqGC}-#nz&s[ pRL$
{n6uDqJVH42pAhB6"3}%Z6\H"MBRX $Vsw!V0ypiQt|

!"#$%&'()*+,-./012345678;<=>[email protected];vSummaryInformation([email protected]@[Microsoft Word 6.02034WXYZUVYZ[\78<=?mno
-.12DEWXabrscU]`U]^`uD\uDZ=>efhiklnoqrst}~,-./?MNQRTU]^_`efghcUcuDcuDcce uD'

/0CD$%CN ""M%^%}%%%%&&&&&&&&&&''''(')'*'O'P'R'S'euccuD
JVHY[>?Xno3c$=>Fe`'`'`'`'F`'`'`'`'`'`'`'`'FxxxxxxxxxxxlT!&efghijklmnopqrstxxxxxxxxx 6 @]@]@@
Pxo(*PxoPxo(*( `''PoPolT!/@AK

ij}[email protected]@@@`'N`'`'K`'`'`'`'f`'`'
4 HH&'()( `'&
4 .
v4 PQ=KL12'(NOCDVab`'`'`'`'`'`'`'x`'`'`'`'`'`'`'`'%`'`'`'`'`'x`'`'`'x`'`'h8VVh8Vl1(.ZJJJD%#B#!19DEV^jk}78ab9Vh888VVVVh8VVh8VVh8VVh8VV`'x`'`'`'`'`'`'x`'`'x`'`'x`'`'`'!DB
H`'`'`'`'`'`'`'x`'`'x`'`'`'`'`'`'x`'`'x`'`'`'`'`'`'`'`'x`'`'x`'`'`'`'`'`'`'x`'`'x`'`'x`'`'`'`'`'`'B!,~ !!!3!I![!j!{!!!!!!!!!""""7"X"b"c""""""""*#Q#e#`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'#,e#f#y######D$E$b$$|%}%&&&&&&&&&&&&&&&&&''(')'*'+'N'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'`'
&&`'&l&&*&`'&*#%N'O'P'Q'R'S'&`'&*[email protected]]a @ Heading 1Uc @ Heading [email protected] 3U"[email protected]"Default Paragraph Font"@"
Normal Indent &'@&Annotation Referencebc @ Annotation Text @" TOC 4`'
@2 TOC 3``'
@B TOC 2`'
"@R"TOC 1`'U* @b*Footer&*[email protected]$Header(*&(O(
List1-Hang O List1-Indent (O(
[email protected]@ O [email protected](O(
List3-Hang`` O List3-Indent`O
List1-Code(O(Normal [email protected]]aO
List3-Code $O$
List2-Code!h"O"Normal Note"VO!
List3-Note%*Oqb*banner2&Pxxo(*4Oqr4banner1'Pxo(*102O2Q&A Question-Hang(``.O.Q&A Answer-Hang)`P`(O(Q&A Question-Indent*`(O(Fix Headings Bug+\&O&Q&A Answer-Indent,`OTen1-Code-(O(Ten1-Hang.P O Ten1-Indent/[email protected]*O"*Ten2-Hang2 O2 Ten2-Indent3OBTen2-Note4&OR&Q&A Answer-Note5V$Ob$Q&A Answer-Code6.Or.Q&A Answer2-Hang7P(O(Q&A Question-Note8V&O&Q&A Question-Code9&O&Q&A Answer2-Indent:$O$Q&A Answer2-Code;.O.Q&A Answer3-Hang$O!$Q&A Answer3-Note?P$O$Q&A [email protected]"O"Normal-NoteAVOhalf-lineBc
,<[email protected]]c0O1B0
Steps textD
,4h.U]tS$S'f'!!!!! t>!S$
\e3456e}P9e#N'S'789:;<=>[email protected][7<-1DWar,MQT]_egS$&&&&&&&&&"9
T$Microsoft Corporation+\\STUK3\PROJECTS\APPNOTES\HF1047\HF1047.DOCMicrosoft CorporationC:\WORD\HF1047.DOCMicrosoft CorporationC:\WORD\HF1047.DOCRichard ClayC:\SHARE\HF1047.DOCMicrosoft CorporationC:\WORD\HF1047.DOCMicrosoft Corporation"\\PLATO\INPROCES\HF1047\HF1047.DOCMicrosoft Corporation"\\PLATO\INPROCES\HF1047\HF1047.DOCSuzanne MorrisonD:\APPNOTES\HF1047\[email protected] LaserJet IIISi PostScriptLPT2:pscriptHP LaserJet IIISi PostScript
od,XZZ^eHP LaserJet IIISi PostScript
od,XZZ^eUUUUWTimes New RomanSymbol&Arial5Courier NewCG Times (W1)"Vheg"UC:\WORD\TEMPLATE\APPNOTE.DOTMicrosoft CorporationSuzanne Morrison;

 December 10, 2017  Add comments

Leave a Reply