VB.NET to Fortran Arrays

VB.NET to Fortran Arrays

I neet to retrieve calculation results in an array, created by the Fortran code: SUBROUTINE GetResults(ANSWERS) !DEC\$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"GetResults" :: GetResults !DEC\$ ATTRIBUTES REFERENCE :: ANSWERS include "GENERAL.INC" REAL ,intent(out)::ANSWERS(10,9,3,10) DO 100 I=1,10 DO 100 J=1,9 DO 100 K=1,3 DO 100 L=1,10 ANSWERS=VBAS(I,J,K,L) 100 CONTINUE RETURN END From vb.net: Private Declare Sub GetResults Lib "SERI.dll" Alias "Results" (ByRef Answers As Single) Dim NewAnswers(0 To 9, 0 To 8, 0 To 2, 0 To 9) As Single GetResults(NewAnswers(0, 0, 0, 0)) For K4 As Integer = 1 To 4 For K1 As Integer = 1 To 3 For K2 As Integer = 1 To 9 For K3 As Integer = 1 To 10 V = NewAnswers(K4 - 1, K2 - 1, K1 - 1, K3 - 1) If V <> 0 Then Debug.Print("New: " & K4.ToString & " " & K2.ToString & " " & K1.ToString & " " & K3.ToString & " " & V.ToString) End If Next Next Next Next This gets results 1 cell at a time, but works: SUBROUTINE Results(LAY,I,J,K,V) !DEC\$ ATTRIBUTES DLLEXPORT,STDCALL,REFERENCE,ALIAS:"Results" :: Results !DEC\$ ATTRIBUTES REFERENCE :: LAY !DEC\$ ATTRIBUTES REFERENCE :: I !DEC\$ ATTRIBUTES REFERENCE :: J !DEC\$ ATTRIBUTES REFERENCE :: K !DEC\$ ATTRIBUTES REFERENCE :: V include "GENERAL.INC" INTEGER ,intent(in)::LAY INTEGER ,intent(in)::I INTEGER ,intent(in)::J INTEGER ,intent(in)::K REAL ,intent(out)::V V=VBAS(LAY,I,J,K) RETURN END Private Declare Sub Results Lib "SERI.dll" Alias "Results" (ByRef LAY As Integer, ByRef I As Integer, ByRef J As Integer, ByRef K As Integer, ByRef V As Single) Dim V As Single Dim Answers(10, 9, 3, 10) As Single For K4 As Integer = 1 To 4 For K1 As Integer = 1 To 3 For K2 As Integer = 1 To 9 For K3 As Integer = 1 To 10 Results(K4, K2, K1, K3, V) Answers(K4 - 1, K2 - 1, K1 - 1, K3 - 1) = V Debug.Print(K4.ToString & " " & K2.ToString & " " & K1.ToString & " " & K3.ToString & " " & V.ToString) Next Next Next Next

2 帖子 / 0 new

Your code got formatted poorly when you pasted it, so I can't read it. I will point you at the two VB-calling-Fortran samples provided with the product under "MixedLanguage" - each uses arrays, one is simple, the other uses SafeArrays.

Steve