Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29279 Discussions

Sending multiple numeric arrays from VB6 to Fortran dll

Intel_C_Intel
Employee
1,507 Views
I can send a single numeric array from VB6 to a Fortran dll reliably. However, I cannot send multiple numeric arrays from VB6 to the dll in a single call. Array values get garbled.

My workaround is to send a a single array with all data, then sort out subarrays in the dll. This is a bit primitive (but it works). Of course, within Fortran alone, multiple arrays are no problem.

Would someone advise on how to send multiple numeric arrays from VB6 to a fortran dll. A simple example would really be appreciated.

Bob Martin
0 Kudos
10 Replies
Intel_C_Intel
Employee
1,507 Views
1- The first array element has number 1 by default in Fortran, but 0 in VB. Therefore you may prefer to declare your arrays in VB as array1(1 To ...). But this is optional.

2- Your arrays must have the same length both in Fortran and VB. They must be of the same data type (Real*8 = Double, Integer = Long, etc.). ByVal should be used only for string variables.

3- Call your DLL from within VB with their first element, i.e. CALL MyDLL(array1(1), array2(1), array3(1),...).

4- Read articles about passing variables between VB and Fortran in 2 following issues of the newsletter:

http://h18009.www1.hp.com/fortran/visual/dvf-news-1.txt
http://h18009.www1.hp.com/fortran/visual/dvf-news-2.txt

Hope this helps.
Sabalan.
0 Kudos
Intel_C_Intel
Employee
1,507 Views
Thanks Sabalan, very clear and helpful. I'll go back to my simple test programs and confirm I have done everything you list.

Bob Martin
0 Kudos
Intel_C_Intel
Employee
1,507 Views
Hi Sabalan,

To the best of my knowledge, I have followed all the rules, but still cant get satisfactory results. In this simple test program (files attached) I call the fortran dll with 2 arrays (both long integers arrays). The dll sums all values to get a total which I then display in VB.
It doesn't work. The module in VB declares the sub as follows: Declare sub fortarray2 lib "c:f_calcsFtest2.dll" (A1 as long, A2 as long, ns as long, Total as long)

I don't know if you have time to look at it, but I would certainly appreciate any assistance you can provide.

Bob Martin
0 Kudos
Intel_C_Intel
Employee
1,507 Views
I saw your Fortran code and copied that into a Dynamic dll project that I created. I only saw the Declare statement and I only changed the capitalization and added Private so I could use it in a form and changed the location and name of the .dll I created. I created the following VB code and it gave the expected result:

Option Explicit
Private Declare Sub FortArray2 Lib "C:ClientsacedevTempdebug emp.dll" (A1 As Long, A2 As Long, ns As Long, total As Long)

Private Sub Form_Load()

Dim A1(1 To 100) As Long
Dim A2(1 To 100) As Long
Dim ns As Long
Dim total As Long

A1(1) = 15
A2(3) = 17
ns = 3
Call FortArray2(A1(1), A2(1), ns, total)
MsgBox total
End Sub

The msgbox gave me a 35.
0 Kudos
Intel_C_Intel
Employee
1,507 Views
Thanks a million, Sabalan.

It appears my problem was in dimensioning the arrays on one line, eg
Dim A1(1 to 100), A2(1 to 100) As Long

Rather than
Dim A1(1 to 100) As Long
Dim A2(1 to 100) As Long

I got the hint for this from your last reply.

It just seems incredible that something like this would hold me up for so long.

Thanks, again.

Bob Martin
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,507 Views
If it's of any consolation -- the same stupid feature held me for two days in one of my rare VB projects. (And that explains why they're gonna stay rare).

Jugoslav
0 Kudos
Intel_C_Intel
Employee
1,507 Views
Bob,

It wasn't me! It was "Sdahl" who helped you. By the way, it is OK to declare variables in one line in VB but you have to specify the type for each of them separately:

Dim A1(1 To 100) As Long, A2(1 To 100) As Long

otherwise the variable is going to take the default type, which is Variant in VB.

Sabalan.
0 Kudos
Intel_C_Intel
Employee
1,507 Views
More good information Sabalan!!

Showing my ignorance still further, I don't know who or what "Sdahl" is. I thank him, her or it and you as the messenger.

Best regards,
Bob Martin
0 Kudos
Intel_C_Intel
Employee
1,507 Views
Bob, you can see the user name of those persons who send messages in the left column of these messages. "Sdahl" is the user name of the person who answered to your second + third messages.

Sabalan.
0 Kudos
Intel_C_Intel
Employee
1,507 Views
Got it, Sabalan.

Much thanks to both you and Sdahl.

Bob
0 Kudos
Reply