Declaring arguments in Fortran procedures callable from Visual Basic and VBA
Most Fortran compilers represent integer, Boolean and real types the same way as Visual Basic and Visual Basic for Applications. Because of this, creating a Fortran procedure that only has arguments of these types is usually a straightforward operation. Developers need to be aware, however, that not all available Fortran types have an equivalent Visual Basic type, and vice versa. Table 4.1 (Chapter 4) shows the most common Fortran and Visual Basic types, with their equivalents in the other language [24].
The most common error when passing these basic types from Visual Basic to Fortran procedures is to forget that they must be passed by reference, because this is the default method used by Fortran (and the only method accepted by some Fortran compilers).
Fortran programmers should not confuse the intent qualifier, used to declare arguments in Fortran procedures, with the method used to pass the arguments. Unless the programmer explicitly indicates otherwise, Fortran procedures (almost) always expect arguments by reference (that is, as pointers to the memory location of the arguments). The intent qualifier, on the other hand, is used by the compiler to identify arguments that can be modified in the scope of the procedure. In the specific case of Visual Basic calling Fortran procedures, arguments passed by value are copied to the calling stack [25], while for arguments passed by reference, a pointer to the memory location of the value is put in the stack.