Value of type '1-dimensional array of double' cannot be converted to double
I'm writing a mixed language program by VB 2005 and Visual Fortran Professional Edition 6.0.0
Fortran part of the program is below:
SUBROUTINE BUCKLE(STN, CHK, SHP, INERTIA, CHK2, LENGTH, R, INC1, INC2, DEF)
!MS$ATTRIBUTES DLLEXPORT::BUCKLE
USE IMSL
DIMENSION INERTIA(110), P(110), DEF(110)
REAL(8), ALLOCATABLE, DIMENSION, :: A
COMPLEX(8), ALLOCATABLE, DIMENSION) :: EVAL
COMPLEX(8), ALLOCATABLE, DIMENSION, :: EVEC
REAL(8) INERTIA, INER, INC1, INC2, LAMDA, CHK, CHK2, DEF
REAL(8) STN, SHP,LENGTH, R
INTEGER LDA, LDEVEC, N
OPEN(1,FILE='OUTPUT.TXT')
LABEL=0
IF(CHK.EQ.1) N=STN-1
IF(CHK.EQ.2) N=STN
ALLOCATE(A(N,N))
ALLOCATE(EVAL(N))
ALLOCATE(EVEC(N,N))
LDA=N
LDEVEC=N
H=LENGTH/STN
IF(CHK.NE.1) GO TO 6
DO 11, I=1, N
DO 12, J=1, N
IF(ABS(I-J).EQ.1) A(I,J)=-1*E*INERTIA(I+1)/(H*H)
IF(I.EQ.J) A(I,J)=2*E*INERTIA(I+1)/(H*H)
12 CONTINUE
11 CONTINUE
GO TO 14
6 CONTINUE
DO 15, I=1, N
DO 16, J=1, N
IF((I.EQ.1).AND.(J.EQ.1)) A(I,J)=2*E*INERTIA(I)/(H*H)
IF((I.EQ.1).AND.(J.EQ.1)) GO TO 16
IF((I.EQ.1).AND.(J.EQ.2)) A(I,J)=-2*E*INERTIA(I)/(H*H)
IF((I.EQ.1).AND.(J.EQ.2)) GO TO 16
IF((I.NE.1).AND.(ABS(I-J).EQ.1)) A(I,J)=-1*E*INERTIA(I)/(H*H)
IF((I.EQ.N).AND.(ABS(I-J).EQ.1)) A(I,J)=-1*E*INERTIA(I)/(H*H)
IF((I.NE.1).AND.(I.EQ.J)) A(I,J)=2*E*INERTIA(I)/(H*H)
16 CONTINUE
15 CONTINUE
14 CALL DEVCRG (N, A, LDA, EVAL, EVEC, LDEVEC)
DO 10 I=1, N
10 P(I)=EVAL(I)
INC1=P(1)
INC2=INC1
M=1
DO 17 I=2, N
IF(P(I).LT.INC1) M=I
IF(P(I).LT.INC1) INC1=P(I)
17 CONTINUE
P(M)=-P(M)
DO 18 I=2, N
18 IF((P(I).LT.INC2).AND.(P(I).GT.0)) INC2=P(I)
P(M)=-P(M)
IF(SHP.EQ.1) LAMDA=INC1
IF(SHP.EQ.2) LAMDA=INC2
DO 22 I=1, N
22 A(I,I)=A(I,I)-LAMDA
DEF(1)=0
DEF(2)=1
IF(CHK.EQ.1) DEF(3)=-DEF(2)*A(1,1)/A(1,2)
IF(CHK.EQ.2) DEF(3)=2*E*INERTIA(1)*R/H-DEF(2)*A(1,1)/A(1,2)
DO 23 I=2, N-1
B=-1
TEMP=0
DO 24 J=I-1, I
B=B+1
TEMP=DEF(B+I)*A(I,J)+TEMP
24 CONTINUE
DEF(I+2)=-TEMP/A(I,I+1)
23 CONTINUE
IF(CHK.EQ.1) DEF(STN+1)=0
DO 26 I=1, STN+1
26 WRITE(1,25) DEF(I)
25 FORMAT(F15.5)
CLOSE(1)
END SUBROUTINE
and here is the VB 2005 Part
Public Class Form1
Private Declare Sub Exe Lib "DynBuck.dll" Alias "Buckle" (ByRef stn As Double, ByRef chk As Double, ByRef shp As Double, ByRef Inertia As Double, ByRef chk2 As Double, ByRef length As Double, ByRef r As Double, ByRef INC1 As Double, ByRef INC2 As Double, ByRef Def As Double)
Dim Act As Integer
Dim Def(110), Chk2, Stn, Chk, Shp As Double
Dim Inertia(110) As Double
Dim INC1, INC2, Length, R As Double
Dim Buffer As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Act = 1
Dim Iner As Double
Dim I As Integer
If Act = 1 Then
Length = CDbl(TextBox1.Text)
Chk = CInt(TextBox3.Text)
Stn = CInt(TextBox2.Text)
If Act = 1 Then
If Chk = 2 Then
R = CDbl(TextBox4.Text)
End If
End If
End If
If Act = 1 Then
Chk2 = CDbl(TextBox7.Text)
End If
If Act = 1 Then
Iner = CDbl(TextBox6.Text)
If Chk2 = 0 Then
For I = 1 To (Stn + 1)
Inertia(I) = Iner
Next
End If
If Chk2 = 1 Then
FileOpen(1, "Inertia.txt", OpenMode.Input)
For I = 1 To (Stn + 1)
Buffer = LineInput(1)
Inertia(I) = CDbl(Trim(Mid(Buffer, 1, 20)))
Next
FileClose(1)
End If
End If
If Act = 1 Then
Shp = CInt(TextBox8.Text)
End If
Exe(Stn, Chk, Shp, Inertia, Chk2, Length, R, INC1, INC2, Def)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
If Act = 1 Then
Label1.Text() = CStr(INC1)
End If
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
If Act = 1 Then
Label2.Text() = CStr(INC2)
End If
End Sub
End Class
I think Fortran Code is Ok but VB code gives the error:
Value of type '1-dimensional array of Double' cannot be converted to 'Double'. for inertia and def parameters in Exe subroutine.
Can you help?
I'm writing a mixed language program by VB 2005 and Visual Fortran Professional Edition 6.0.0
Fortran part of the program is below:
SUBROUTINE BUCKLE(STN, CHK, SHP, INERTIA, CHK2, LENGTH, R, INC1, INC2, DEF)
!MS$ATTRIBUTES DLLEXPORT::BUCKLE
USE IMSL
DIMENSION INERTIA(110), P(110), DEF(110)
REAL(8), ALLOCATABLE, DIMENSION, :: A
COMPLEX(8), ALLOCATABLE, DIMENSION) :: EVAL
COMPLEX(8), ALLOCATABLE, DIMENSION, :: EVEC
REAL(8) INERTIA, INER, INC1, INC2, LAMDA, CHK, CHK2, DEF
REAL(8) STN, SHP,LENGTH, R
INTEGER LDA, LDEVEC, N
OPEN(1,FILE='OUTPUT.TXT')
LABEL=0
IF(CHK.EQ.1) N=STN-1
IF(CHK.EQ.2) N=STN
ALLOCATE(A(N,N))
ALLOCATE(EVAL(N))
ALLOCATE(EVEC(N,N))
LDA=N
LDEVEC=N
H=LENGTH/STN
IF(CHK.NE.1) GO TO 6
DO 11, I=1, N
DO 12, J=1, N
IF(ABS(I-J).EQ.1) A(I,J)=-1*E*INERTIA(I+1)/(H*H)
IF(I.EQ.J) A(I,J)=2*E*INERTIA(I+1)/(H*H)
12 CONTINUE
11 CONTINUE
GO TO 14
6 CONTINUE
DO 15, I=1, N
DO 16, J=1, N
IF((I.EQ.1).AND.(J.EQ.1)) A(I,J)=2*E*INERTIA(I)/(H*H)
IF((I.EQ.1).AND.(J.EQ.1)) GO TO 16
IF((I.EQ.1).AND.(J.EQ.2)) A(I,J)=-2*E*INERTIA(I)/(H*H)
IF((I.EQ.1).AND.(J.EQ.2)) GO TO 16
IF((I.NE.1).AND.(ABS(I-J).EQ.1)) A(I,J)=-1*E*INERTIA(I)/(H*H)
IF((I.EQ.N).AND.(ABS(I-J).EQ.1)) A(I,J)=-1*E*INERTIA(I)/(H*H)
IF((I.NE.1).AND.(I.EQ.J)) A(I,J)=2*E*INERTIA(I)/(H*H)
16 CONTINUE
15 CONTINUE
14 CALL DEVCRG (N, A, LDA, EVAL, EVEC, LDEVEC)
DO 10 I=1, N
10 P(I)=EVAL(I)
INC1=P(1)
INC2=INC1
M=1
DO 17 I=2, N
IF(P(I).LT.INC1) M=I
IF(P(I).LT.INC1) INC1=P(I)
17 CONTINUE
P(M)=-P(M)
DO 18 I=2, N
18 IF((P(I).LT.INC2).AND.(P(I).GT.0)) INC2=P(I)
P(M)=-P(M)
IF(SHP.EQ.1) LAMDA=INC1
IF(SHP.EQ.2) LAMDA=INC2
DO 22 I=1, N
22 A(I,I)=A(I,I)-LAMDA
DEF(1)=0
DEF(2)=1
IF(CHK.EQ.1) DEF(3)=-DEF(2)*A(1,1)/A(1,2)
IF(CHK.EQ.2) DEF(3)=2*E*INERTIA(1)*R/H-DEF(2)*A(1,1)/A(1,2)
DO 23 I=2, N-1
B=-1
TEMP=0
DO 24 J=I-1, I
B=B+1
TEMP=DEF(B+I)*A(I,J)+TEMP
24 CONTINUE
DEF(I+2)=-TEMP/A(I,I+1)
23 CONTINUE
IF(CHK.EQ.1) DEF(STN+1)=0
DO 26 I=1, STN+1
26 WRITE(1,25) DEF(I)
25 FORMAT(F15.5)
CLOSE(1)
END SUBROUTINE
and here is the VB 2005 Part
Public Class Form1
Private Declare Sub Exe Lib "DynBuck.dll" Alias "Buckle" (ByRef stn As Double, ByRef chk As Double, ByRef shp As Double, ByRef Inertia As Double, ByRef chk2 As Double, ByRef length As Double, ByRef r As Double, ByRef INC1 As Double, ByRef INC2 As Double, ByRef Def As Double)
Dim Act As Integer
Dim Def(110), Chk2, Stn, Chk, Shp As Double
Dim Inertia(110) As Double
Dim INC1, INC2, Length, R As Double
Dim Buffer As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Act = 1
Dim Iner As Double
Dim I As Integer
If Act = 1 Then
Length = CDbl(TextBox1.Text)
Chk = CInt(TextBox3.Text)
Stn = CInt(TextBox2.Text)
If Act = 1 Then
If Chk = 2 Then
R = CDbl(TextBox4.Text)
End If
End If
End If
If Act = 1 Then
Chk2 = CDbl(TextBox7.Text)
End If
If Act = 1 Then
Iner = CDbl(TextBox6.Text)
If Chk2 = 0 Then
For I = 1 To (Stn + 1)
Inertia(I) = Iner
Next
End If
If Chk2 = 1 Then
FileOpen(1, "Inertia.txt", OpenMode.Input)
For I = 1 To (Stn + 1)
Buffer = LineInput(1)
Inertia(I) = CDbl(Trim(Mid(Buffer, 1, 20)))
Next
FileClose(1)
End If
End If
If Act = 1 Then
Shp = CInt(TextBox8.Text)
End If
Exe(Stn, Chk, Shp, Inertia, Chk2, Length, R, INC1, INC2, Def)
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
If Act = 1 Then
Label1.Text() = CStr(INC1)
End If
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
If Act = 1 Then
Label2.Text() = CStr(INC2)
End If
End Sub
End Class
I think Fortran Code is Ok but VB code gives the error:
Value of type '1-dimensional array of Double' cannot be converted to 'Double'. for inertia and def parameters in Exe subroutine.
Can you help?