Passing FORTRAN COMMON Block to QuickBasic SUBprogram (27480)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b

This article was previously published under Q27480

SUMMARY

The strategy for passing a FORTRAN COMMON block to QuickBasic is to pass the first variable of the FORTRAN COMMON block as a parameter in the CALL to the Basic routine. The Basic program should set up a user-defined-TYPE variable with the same format as the COMMON in FORTRAN. The Basic SUB statement must receive a variable of this type as a formal parameter.

MORE INFORMATION

Basic Program

The Basic program is as follows:
DECLARE SUB forsub ()

TYPE CommonDescription
  a AS INTEGER             'Matches common block in FORTRAN
  b AS LONG
  c AS SINGLE
  d AS DOUBLE
END TYPE

CALL forsub

SUB subbas (var AS CommonDescription)
  PRINT var.a
  PRINT var.b
  PRINT var.c
  PRINT var.d
END SUB
				

FORTRAN Subroutine

The FORTRAN subroutine is as follows:
       INTERFACE TO SUBROUTINE SUBBAS (N1)
       INTEGER*2 N1 [NEAR]
       END

       SUBROUTINE FORSUB
       INTEGER*2 A
       INTEGER*4 B
       REAL*4 C
       REAL*8 D

      *The common block must be a named common block (any name will do).
      *The [NEAR] has to be there for it to work.

       COMMON /FORBLOCK [NEAR]/ A,B,C,D
       A = 9
       B = 999
       C = 99.99
       D = 999.999
       CALL SUBBAS(A)
       END
				

OUTPUT

The OUTPUT is as follows:

9
999
99.99
999.999


Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB27480