From: Cem Girit on
Hi,

I have an vb application that requires a Matlab dll. By using Com
builder I created a dll which I then load into VB program. But when I
run the VB program I get the following error message where the dll
call is made:

"Error: Subscript indices must either be real positive integers or
logicals"

I have no idea why? As it can be seen from the listings of both VB
and Matlab files, I believe I do right type conversions. When I run
the Matlab code in Matlab, it works fine. The two input arguments to
routine are ascdata and miss. ascdata is 245985x1 double array, miss
is 5205x1 double array. The only output argument (v) is defined as
variant.

Please help. I am stuck!

Cem

------------------------------
Matlab program:

function [v]=TestVBD(ascdata,miss)
persistent mask rho x1 x2 rc is js

m=512;
n=172;
N_hit=82859;
init_done=0;

%read and reshape data
raw=reshape(ascdata,[3,N_hit]);

%convert data to image format
image=Scan2Image(raw,m,n,miss);
......

-----------------------------------------
VB program:

Option Explicit

Dim x() As Double
Dim y() As Double
Dim z() As Double
Dim miss() As Double
Dim ascdata() As Double

Dim objTest As TestVBD.Test ' Variable to hold the COM object

Private Sub Form_Initialize()

On Error GoTo Handle_Error

init_done = 0
Set objTest = New TestVBD.Test
' Set the flags such that the input is always passed as double
data
objTumor.MWFlags.DataConversionFlags.CoerceNumericToType =
mwTypeDouble

' Check if the object was created properly ' If not then go to
the error handling routine
If objTumor Is Nothing Then
MsgBox "Test calculation routine is not loaded. Please
restart program.", vbCritical
Exit Sub
End If

Exit Sub

Handle_Error:
' Error handling code
MsgBox ("Error " & Err.Description)

End Sub

Private Sub cmdCalcV_Click()

Dim volume As Variant

' If there is an error then keep continuing with the code
On Error GoTo Handle_Error

Call TestVBD.Test(1, v, ascdata, miss)

Exit Sub

Handle_Error:
' Error handling routine
MsgBox ("Error: " & Err.Description)

End Sub

Private Sub ReadData()

Dim fNum As Integer
Dim fname As String
Dim i As Long
Dim j As Long

fNum = FreeFile
fname = "c:\t1-2.par"
Open fname For Input As #fNum

Input #fNum, m
Input #fNum, n
Input #fNum, N_hit

ReDim x(1 To N_hit)
ReDim y(1 To N_hit)
ReDim z(1 To N_hit)
ReDim miss(1 To m * n - N_hit)
ReDim Sizes(1 To n)
ReDim ascdata(1 To 3 * N_hit)

Dim k As Long

For i = 1 To m * n - N_hit
Input #fNum, miss(i)
Next

Close #fNum

fname = Replace(fname, "par", "asc")

fNum = FreeFile
Open fname For Input As #fNum

k = 1
For i = 1 To N_hit
Input #fNum, x(i), y(i), z(i)
ascdata(k) = x(i)
ascdata(k + 1) = y(i)
ascdata(k + 2) = z(i)
k = k + 3
Next

Close #fNum

End Sub

Private Sub Form_Load()

ReadData

End Sub
From: Cem Girit on
Cem Girit wrote:

I solved my problem. Here is the lesson I've got after 4 days of
intensive debuging:

Matlab doesn't use 0 based arrays, but VB does. I had a line;
test(miss)=0;. The first element of the "miss" array was 0!. Thank
you for those who at least read my posting.

Cem
>
>
> Hi,
>
> I have an vb application that requires a Matlab dll. By using
> Com
> builder I created a dll which I then load into VB program. But when
> I
> run the VB program I get the following error message where the dll
> call is made:
>
> "Error: Subscript indices must either be real positive integers or
> logicals"
>
> I have no idea why? As it can be seen from the listings of both
> VB
> and Matlab files, I believe I do right type conversions. When I run
> the Matlab code in Matlab, it works fine. The two input arguments
> to
> routine are ascdata and miss. ascdata is 245985x1 double array,
> miss
> is 5205x1 double array. The only output argument (v) is defined as
> variant.
>
> Please help. I am stuck!
>
> Cem
>
> ------------------------------
> Matlab program:
>
> function [v]=TestVBD(ascdata,miss)
> persistent mask rho x1 x2 rc is js
>
> m=512;
> n=172;
> N_hit=82859;
> init_done=0;
>
> %read and reshape data
> raw=reshape(ascdata,[3,N_hit]);
>
> %convert data to image format
> image=Scan2Image(raw,m,n,miss);
> .....
>
> -----------------------------------------
> VB program:
>
> Option Explicit
>
> Dim x() As Double
> Dim y() As Double
> Dim z() As Double
> Dim miss() As Double
> Dim ascdata() As Double
>
> Dim objTest As TestVBD.Test ' Variable to hold the COM object
>
> Private Sub Form_Initialize()
>
> On Error GoTo Handle_Error
>
> init_done = 0
> Set objTest = New TestVBD.Test
> ' Set the flags such that the input is always passed as double
> data
> objTumor.MWFlags.DataConversionFlags.CoerceNumericToType =
> mwTypeDouble
>
> ' Check if the object was created properly ' If not then go to
> the error handling routine
> If objTumor Is Nothing Then
> MsgBox "Test calculation routine is not loaded. Please
> restart program.", vbCritical
> Exit Sub
> End If
>
> Exit Sub
>
> Handle_Error:
> ' Error handling code
> MsgBox ("Error " & Err.Description)
>
> End Sub
>
> Private Sub cmdCalcV_Click()
>
> Dim volume As Variant
>
> ' If there is an error then keep continuing with the code
> On Error GoTo Handle_Error
>
> Call TestVBD.Test(1, v, ascdata, miss)
>
> Exit Sub
>
> Handle_Error:
> ' Error handling routine
> MsgBox ("Error: " & Err.Description)
>
> End Sub
>
> Private Sub ReadData()
>
> Dim fNum As Integer
> Dim fname As String
> Dim i As Long
> Dim j As Long
>
> fNum = FreeFile
> fname = "c:\t1-2.par"
> Open fname For Input As #fNum
>
> Input #fNum, m
> Input #fNum, n
> Input #fNum, N_hit
>
> ReDim x(1 To N_hit)
> ReDim y(1 To N_hit)
> ReDim z(1 To N_hit)
> ReDim miss(1 To m * n - N_hit)
> ReDim Sizes(1 To n)
> ReDim ascdata(1 To 3 * N_hit)
>
> Dim k As Long
>
> For i = 1 To m * n - N_hit
> Input #fNum, miss(i)
> Next
>
> Close #fNum
>
> fname = Replace(fname, "par", "asc")
>
> fNum = FreeFile
> Open fname For Input As #fNum
>
> k = 1
> For i = 1 To N_hit
> Input #fNum, x(i), y(i), z(i)
> ascdata(k) = x(i)
> ascdata(k + 1) = y(i)
> ascdata(k + 2) = z(i)
> k = k + 3
> Next
>
> Close #fNum
>
> End Sub
>
> Private Sub Form_Load()
>
> ReadData
>
> End Sub
From: Mr Hrundi V Bakshi on
In VB.NYT follow Option Explicit by Option Base 1 with which VB and Matlab
have 1-based arrays stored in column-major order. However, in VB.NET,
arrays are 0-based and in row-major order just like in C.