array as object problem

M

mp

Before I set option strict on i was able to work with arrays as objects
similar to vb6 variants
what i mean by that is the following lines worked in my app
Dim vMin As Object = Nothing, vMax As Object = Nothing

oRegion.GetBoundingBox(vMin, vMax)

and the GetBoundingBox method filled the arrays as required (3 element
arrays of doubles)

..................

when i changed to option strict on i had to change the lines above to

Dim vMin As Double() = New Double(0 To 2) {}

Dim vMax As Double() = New Double(0 To 2) {}

'convert array to object

oRegion.GetBoundingBox(CType(vMin, Object), CType(vMax, Object))

but now the arrays are not filled...they appear to be all zeros

how do i solve this dilema?

the .GetBoundingBox method args are (vMin as Object, vMax as Object)

in vb6 they would have been variants and would return 3 element arrays of
doubles

thanks

mark
 
A

Armin Zingler

Am 14.07.2010 17:17, schrieb mp:
Before I set option strict on i was able to work with arrays as objects
similar to vb6 variants
what i mean by that is the following lines worked in my app
Dim vMin As Object = Nothing, vMax As Object = Nothing

oRegion.GetBoundingBox(vMin, vMax)

and the GetBoundingBox method filled the arrays as required (3 element
arrays of doubles)

.................

when i changed to option strict on i had to change the lines above to

Dim vMin As Double() = New Double(0 To 2) {}

Dim vMax As Double() = New Double(0 To 2) {}

'convert array to object

oRegion.GetBoundingBox(CType(vMin, Object), CType(vMax, Object))

but now the arrays are not filled...they appear to be all zeros

how do i solve this dilema?

the .GetBoundingBox method args are (vMin as Object, vMax as Object)

in vb6 they would have been variants and would return 3 element arrays of
doubles

Why not declare
GetBoundingBox (byref vMin as double(), byref vMax as double())
?
Then you can just call
oRegion.GetBoundingBox(vMin, vMax)
like before.


The reason that it doesn't work with "CType(vMin, Object)" is that
"CType(vMin, Object)" is an expression. Before the method is called,
the expression is calculated and stored in a temporary place.
Inside GetBoundingBox, the content does change, but after the method
returns you don't have access to that temporary value.
 
M

mp

Thanks Armin, see below

Armin Zingler said:
Am 14.07.2010 17:17, schrieb mp:

Why not declare
GetBoundingBox (byref vMin as double(), byref vMax as double())
?

Because I didn't write it - that is a method on an autocad object

Then you can just call
oRegion.GetBoundingBox(vMin, vMax)
like before.


The reason that it doesn't work with "CType(vMin, Object)" is that
"CType(vMin, Object)" is an expression. Before the method is called,
the expression is calculated and stored in a temporary place.
Inside GetBoundingBox, the content does change, but after the method
returns you don't have access to that temporary value.

so can I do like:
Dim oVarMin as Object
oVarMin = Ctype(vMin, Object)
???
would that capture the permanent object?
then do GetBoundingBox(oVarMin, oVarMax)
?
guess i'll try and find out

 
A

Armin Zingler

Am 14.07.2010 20:58, schrieb mp:
Because I didn't write it - that is a method on an autocad object

Ah, ok. See below.
so can I do like:
Dim oVarMin as Object
oVarMin = Ctype(vMin, Object)
???
would that capture the permanent object?
then do GetBoundingBox(oVarMin, oVarMax)
?
guess i'll try and find out


Are the arrays only output parameters or also input parameters?

If both:

Dim oVarMin as Object = vMin
Dim oVarMax as Object = vMax

oRegion.GetBoundingBox(oVarMin , oVarMax )

vMin = directcast(oVarMin, double())
vMax = directcast(oVarMax, double())


Otherwise: just leave out "= vMin" and "= vMax" in the declaration
lines.
 
M

mp

Armin Zingler said:
Am 14.07.2010 20:58, schrieb mp:

Ah, ok. See below.



Are the arrays only output parameters or also input parameters?

If both:

Dim oVarMin as Object = vMin
Dim oVarMax as Object = vMax

oRegion.GetBoundingBox(oVarMin , oVarMax )

vMin = directcast(oVarMin, double())
vMax = directcast(oVarMax, double())


Otherwise: just leave out "= vMin" and "= vMax" in the declaration
lines.

awesome,
thanks
mark
 
M

mp

Armin Zingler said:
Am 14.07.2010 20:58, schrieb mp:

Ah, ok. See below.



Are the arrays only output parameters or also input parameters?

If both:

Dim oVarMin as Object = vMin
Dim oVarMax as Object = vMax

oRegion.GetBoundingBox(oVarMin , oVarMax )

vMin = directcast(oVarMin, double())
vMax = directcast(oVarMax, double())


Otherwise: just leave out "= vMin" and "= vMax" in the declaration
lines.

thanks Armin,
I tried that, don't know why it's still not working here.
I'll keep trying
mark
 
A

Armin Zingler

Am 20.07.2010 19:32, schrieb mp:
thanks Armin,
I tried that, don't know why it's still not working here.
I'll keep trying
mark

What's not working? I guess it's compilable. Getting an Exception?
If the cast is invalid, examine oVarMin and oVarMax straight
after GetBoundingBox returns.
 
M

mp

Armin Zingler said:
Am 20.07.2010 19:32, schrieb mp:

What's not working? I guess it's compilable. Getting an Exception?
If the cast is invalid, examine oVarMin and oVarMax straight
after GetBoundingBox returns.

I think it's finally working. I had read your post and thought i'd revised
the code accordingly but after so many edits i had some crap floating
around. finally i just cut and pasted your code, using the new variables
and starting from scratch, so yes your code works. Thanks.
mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top