Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value of type '1-dimensional array of Double' cannot be converted to

Status
Not open for further replies.

Mythrem

Technical User
May 6, 2008
9
TR
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?
 
[tt]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)
[/tt]


[tt] Dim Def(110), Chk2, Stn, Chk, Shp As Double
Dim Inertia(110) As Double
[/tt]


[tt] Exe(Stn, Chk, Shp, Inertia, Chk2, Length, R, INC1, INC2, Def)
[/tt]


In the Declare parameters you have Inertia and Def as doubles, however the values you are attempting to assign are 1-Dimensional arrays of double.

You need to make sure that declaration parameters and the passed values match.


Hope this helps.

[vampire][bat]
 
Ok they dont match but how should I define Inertia and Def in program and in exe(.....) part?
 
Ok I wrote
Exe(Stn, Chk, Shp, Inertia(110), Chk2, Length, R, INC1, INC2, Def(110)) and the error seems to be corrected but after following the steps i saw that inc1 and inc2 -these are values returned from fortran, were empty...
What is the problem? why inc1 and inc2 are not published in labels when act is turned into 1?
 
[tt]Exe(Stn, Chk, Shp, Inertia(110), Chk2, Length, R, INC1, INC2, Def(110)) [/tt]

This only passes the single element at Inertia(110) and at Def(110), because the declaration is expecting 1 double datatype value for each of those parameters.

My guess would be that you need to adjust the Declare statement to either:

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)

which indicates an array at those positions

or:

Private Declare Sub Exe Lib "DynBuck.dll" Alias "Buckle" (ByRef stn As Double, ByRef chk As Double, ByRef shp As Double, ByRef Inertia(110) As Double, ByRef chk2 As Double, ByRef length As Double, ByRef r As Double, ByRef INC1 As Double, ByRef INC2 As Double, ByRef Def(110) As Double)

which specifies the size of the array as well.

But as I've never had to pass an array to an external routine in this way, I can't say for sure.


Hope this helps.

[vampire][bat]
 
Thanks for the suggestion but it does not work...
When I put empty paranthesis, the same error massage is generated and when I insert 110 into paranthesis, compilation rejects them.
 
I don't "speak" Fortran, but possibly the declaration of the routine there is the problem:

SUBROUTINE BUCKLE(STN, CHK, SHP, INERTIA, CHK2, LENGTH, R, INC1, INC2, DEF)


Is it possible to indicate there that an array is expected?

If so, then it maybe possible to use one of my earlier suggestions.

[vampire][bat]
 
One other point worth mentioning:

[tt]Dim Inertia(110) As Double[/tt]

declares a 111 element array with elements from 0 to 110 inclusive.

[tt]INERTIA(110)[/tt] - does this declare a 110 element array with elements from 1 to 110? If so then the VB declaration needs to be changed to [tt]Dim Inertia(109) As Double[/tt]

[vampire][bat]
 
I think I've solved it:

Leave this unchanged:

[tt]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)[/tt]


Change:
[tt] Dim Def(110), Chk2, Stn, Chk, Shp As Double
Dim Inertia(110) As Double
[/tt]

to:
[tt] Dim Def(109), Chk2, Stn, Chk, Shp As Double
Dim Inertia(109) As Double
[/tt]


and change:
[tt]Exe(Stn, Chk, Shp, Inertia, Chk2, Length, R, INC1, INC2, Def)
[/tt]

to:
[tt]Exe(Stn, Chk, Shp, Inertia(0), Chk2, Length, R, INC1, INC2, Def(0))
[/tt]

Additionally, change all references to the subscripts for Inertia and Def from (for example): [tt]Inertia(I) = Iner[/tt] to: [tt]Inertia(I-1) = Iner[/tt] to handle the fact that VB is 0-based and your Fortran declarations are (presumably) 1-based.


Info and explanations from:


Hope this helps.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top