Help with late binding converting an object to an array 
Author Message
 Help with late binding converting an object to an array

Hi,

How do I convert a variable of type object to an array (without turning off
Option Strict) ?

Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim obj As Object
obj = arr
if obj.GetType.IsArray Then
For i = 0 to obj.GetUpperBound(0)
    Console.writeline(obj(i))
Next
End If

Many thanks
Jeremy Holt



Tue, 13 Jul 2004 02:35:22 GMT  
 Help with late binding converting an object to an array
Jeremy,
    You might want to have a look at the System.Convert.ChangeType method.

Jason


Quote:
> Hi,

> How do I convert a variable of type object to an array (without turning
off
> Option Strict) ?

> Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
> Dim obj As Object
> obj = arr
> if obj.GetType.IsArray Then
> For i = 0 to obj.GetUpperBound(0)
>     Console.writeline(obj(i))
> Next
> End If

> Many thanks
> Jeremy Holt



Tue, 13 Jul 2004 02:41:03 GMT  
 Help with late binding converting an object to an array

  Jason,

  Thanks, however, I found an easier way in the end:

  Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
  Dim obj As Object
  Dim i As Integer

  obj = arr

  Dim a As Integer() = CType(obj, Integer())
  For i = 0 To a.GetUpperBound(0)
      Console.WriteLine(a(i))
  Next

  Regards
  Jeremy

Quote:

> Jeremy,
>     You might want to have a look at the System.Convert.ChangeType method.

> Jason



> > Hi,

> > How do I convert a variable of type object to an array (without turning
> off
> > Option Strict) ?

> > Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
> > Dim obj As Object
> > obj = arr
> > if obj.GetType.IsArray Then
> > For i = 0 to obj.GetUpperBound(0)
> >     Console.writeline(obj(i))
> > Next
> > End If

> > Many thanks
> > Jeremy Holt



Tue, 13 Jul 2004 02:55:27 GMT  
 Help with late binding converting an object to an array
Hey, whatever works right? ;-)


Jason,

Thanks, however, I found an easier way in the end:

Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim obj As Object
Dim i As Integer

obj = arr

Dim a As Integer() = CType(obj, Integer())
For i = 0 To a.GetUpperBound(0)
    Console.WriteLine(a(i))
Next

Regards
Jeremy


Quote:
> Jeremy,
>     You might want to have a look at the System.Convert.ChangeType method.

> Jason



> > Hi,

> > How do I convert a variable of type object to an array (without turning
> off
> > Option Strict) ?

> > Dim arr As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
> > Dim obj As Object
> > obj = arr
> > if obj.GetType.IsArray Then
> > For i = 0 to obj.GetUpperBound(0)
> >     Console.writeline(obj(i))
> > Next
> > End If

> > Many thanks
> > Jeremy Holt



Tue, 13 Jul 2004 03:05:16 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. late binding privDBEngine object

2. TOUGH Question - Late Bound COM objects and VB.NET

3. Late Bound Intertaction with objects

4. Create Object But NOT Late Binding

5. Late binding enum object

6. Using Late Bound Object in Class - Stange Results

7. late binding creating ADO objects / CLSID / correct syntax

8. early binding vs late binding

9. Activex Server - Early Binding vs. Late Binding

10. Late Binding vs Early Binding in out-of-process servers

11. * Early binding or late binding

12. Early binding and Late binding

 

 
Powered by phpBB® Forum Software