array as object problem

  • Thread starter Thread starter mp
  • Start date Start date
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
 
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.
 
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

 
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.
 
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
 
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
 
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.
 
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
 
Back
Top