>> > Hello,
>> > Newbie here and I need your help.
>> > I am trying to pass some strings from VB 6.0 to a Fortran 90 program
>and
>> > then retrive the results (string) from Fortran 90 into VB 6.0
>> > Anyone has any idea how this can be done.
>> > Thanks very much for pointing me in the right direction
>> What compiler? CVF has good mixed-language programming section and
>> samples...
>> try
>> http://h18009.www1.hp.com/fortran/docs/vf-html/vf_frame.htm
>Sorry, I intended to paste the following snippet from there, too,
>although I'd recommend strongly reading the section as VB has special
>requirements for strings and arrays in particular...
>Visual Basic strings must be passed by value to Fortran. Visual Basic
>strings are actually stored as structures containing length and location
>information. Passing by value dereferences the structure and passes just
>the string location, as Fortran expects.
>For example:
> ! In Basic
> Declare Sub forstr Lib "forstr.dll" (ByVal Bstring as String)
> DIM bstring As String * 40 Fixed-length string
> CALL forstr(bstring)
> ! End Basic code
> ! In Fortran
> SUBROUTINE forstr(s)
> !DEC$ ATTRIBUTES STDCALL :: forstr
> !DEC$ ATTRIBUTES REFERENCE :: s
> CHARACTER(40) s
> s = 'Hello, Visual Basic!'
> END
>Obviously the Fortran side will be compiler-specific to incorporate the
>equivalence of the STDCALL and REFERENCE directives of CVF...
Just a side thought here.... If you intend to use your code well into the future... or rather... to
recompile your fortran code in the future... you "might" give some
consideration to writing your string data to an intermediate disk file and have
the "other" program read it from there. This method has the distinct advantage
of more portability over the long haul. As Duane pointed out... his solution
is specific to the DVF Fortran compiler and is not guaranteed with any other
compiler ( including later versions of the DVF ( now Intel ) compiler ).
The actual passing mechanism which a fortran compiler implements is specific to
the compiler. If you make an assumption such as "pass by reference" or "pass
by value" and things work ok, just be clear that you can't necessarily depend
on that behavior.