PC Review


Reply
Thread Tools Rate Thread

array as object problem

 
 
mp
Guest
Posts: n/a
 
      14th Jul 2010

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




 
Reply With Quote
 
 
 
 
Armin Zingler
Guest
Posts: n/a
 
      14th Jul 2010
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.

--
Armin
 
Reply With Quote
 
mp
Guest
Posts: n/a
 
      14th Jul 2010
Thanks Armin, see below

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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())
> ?


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


> --
> Armin



 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      14th Jul 2010
Am 14.07.2010 20:58, 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


Ah, ok. See below.

>> 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



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
 
Reply With Quote
 
mp
Guest
Posts: n/a
 
      14th Jul 2010

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Am 14.07.2010 20:58, 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

>
> Ah, ok. See below.
>
>>> 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

>
>
> 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


awesome,
thanks
mark


 
Reply With Quote
 
mp
Guest
Posts: n/a
 
      20th Jul 2010

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Am 14.07.2010 20:58, 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

>
> Ah, ok. See below.
>
>>> 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

>
>
> 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


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


 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      20th Jul 2010
Am 20.07.2010 19:32, schrieb mp:
>> 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


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
 
Reply With Quote
 
mp
Guest
Posts: n/a
 
      21st Jul 2010

"Armin Zingler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Am 20.07.2010 19:32, schrieb mp:
>>> 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

>
> 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


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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with an object of multidimensional array Chris Lee Microsoft VB .NET 4 28th Jun 2004 01:31 AM
Problem converting VB6 Variant array to object Jim Johnston Microsoft VB .NET 0 12th Mar 2004 01:42 AM
Conversion problem object to array Microsoft C# .NET 1 20th Feb 2004 09:11 PM
Problem passing object array to Web service Roger Bonine Microsoft VB .NET 0 28th Jan 2004 08:26 PM
Problem with object to array convertion Jeroen Ceuppens Microsoft C# .NET 2 9th Sep 2003 01:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:37 PM.