replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Excel VBA: Bad DLL calling convention
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Excel VBA: Bad DLL calling convention

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
MGGM



Joined: 20 Aug 2012
Posts: 5

PostPosted: Tue Aug 21, 2012 3:45 pm    Post subject: Excel VBA: Bad DLL calling convention Reply with quote

Hi again!

The second problem I'm encountering with a different attempt at using a FORTAN subroutine from Excel-VBA is the error "Bad DLL calling convention"

This is the FORTRAN code (statistical algorithm AS62, it computes Mann-Whitney U distribution):

SUBROUTINE UDIST(M, N, FRQNCY, LFR, WORK, LWRK, IFAULT)
!dec$ attributes dllexport, stdcall, alias:'UDIST', :: UDIST

REAL FRQNCY(LFR), WORK(LWRK)
INTEGER MINMN, MN1, MAXMN, N1, I, IN, L, K, J
REAL ZERO, ONE, SUM
DATA ZERO /0.0/, ONE /1.0/
IFAULT = 1
MINMN = MIN(M, N)
IF (MINMN .LT. 1) RETURN
IFAULT = 2
MN1 = M * N + 1
IF (LFR .LT. MN1) RETURN
MAXMN = MAX(M, N)
N1 = MAXMN + 1
DO 1 I = 1, N1
1 FRQNCY(I) = ONE
IF (MINMN .EQ. 1) GO TO 4
IFAULT = 3
IF (LWRK .LT. (MN1 + 1) / 2 + MINMN) RETURN
N1 = N1 + 1
DO 2 I = N1, MN1
2 FRQNCY(I) = ZERO
WORK(1) = ZERO
IN = MAXMN
DO 3 I = 2, MINMN
WORK(I) = ZERO
IN = IN + MAXMN
N1 = IN + 2
L = 1 + IN / 2
K = I
DO 3 J = 1, L
K = K + 1
N1 = N1 - 1
SUM = FRQNCY(J) + WORK(J)
FRQNCY(J) = SUM
WORK(K) = SUM - FRQNCY(N1)
FRQNCY(N1) = SUM
3 CONTINUE
4 IFAULT = 0
SUM = ZERO
DO 10 I = 1, MN1
SUM = SUM + FRQNCY(I)
FRQNCY(I) = SUM
10 END DO
DO 20 I = 1, MN1
20 FRQNCY(I) = FRQNCY(I) / SUM
RETURN

END


This is the VBA side:

Option Base 1
Option Explicit
Private Declare Sub UDIST Lib "E:\Test\AS62.dll" _
(m As Long, _
n As Long, _
frqncy As Single, _
lfr As Long, _
work As Single, _
lwrk As Long, _
ifault As Long)
Public Function UPROB(m As Long, n As Long, U As Long) As Variant
On Error GoTo errtrap

Dim minmn As Long, frqncy() As Single, lfr As Long, work() As Single, lwrk As Long, ifault As Long

minmn = Application.WorksheetFunction.Min(m, n)
lfr = m * n + 1
lwrk = 2 + Int(minmn + (lfr + 1) / 2)
ReDim work(lwrk)
ReDim frqncy(lfr)

Call UDIST(m, n, frqncy(1), lfr, work(1), lwrk, ifault)

' If ll is OK, get the frecuency for U value - first value is U=0
UPROB = frqncy(U+1)

' Error trap to find out the malfunctioning cause
errtrap:
UPROB = Err.Description

End Function

Any ideas?

Thanks,
Marta GG
Back to top
View user's profile Send private message
MGGM



Joined: 20 Aug 2012
Posts: 5

PostPosted: Thu Aug 23, 2012 7:52 am    Post subject: Close the thread Reply with quote

Hi

Since I wasn't able to find a solution (neither anyone else who read the message, I finally took a different approach and translated the FORTRAN subroutine to VBA. Anyway, I wish I could have solved it!

Consider the thread closed.

Marta GG
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group