create/use array of different classes?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Ron (anonymous_at_discussions.microsoft.com)
Date: 10/07/04


Date: Thu, 7 Oct 2004 14:29:58 -0700

Well, I came up with one solution that isn't real dynamic,
but it seems to work:

For i As Integer = 1 to dts.Length
 If i = 1 Then Ctype(dts(i), clsDTS1).DataPath = strPath(i)
 If i = 2 Then Ctype(dts(i), clsDTS2).DataPath = strPath(i)
 If i = 3 Then Ctype(dts(i), clsDTS3).DataPath = strPath(i)
 If i = 4 Then Ctype(dts(i), clsDTS4).DataPath = strPath(i)
...

Any suggestions appreciated if there is a better way.

>-----Original Message-----
>Hello,
>
>I have 4 classes that use 4 DTS packages on 4 different
>tables. So I have
>Dim cls1 As New clsDTS1, cls2 As New clsDTS2
>Dim cls3 As New clsDTS3, cls4 As New clsDTS4
>
>Each class has a common property called DataPath
>cls1.DataPath = strPath
>
>I want to use these classes in a loop, so I need to put
>them in some kind of array. Obviously I can't use a
class
>array because they are all different classes. So I tried
>using an object array like this:
>
>Dim dts() As Object = {cls1, cls2, cls3, cls4}
>For i As Integer = 0 To dts.Length - 1
> Ctype(dts(i), dts(i)).DataPath = strPath(i)
>....
>
>I had a problem with Ctype(dts(i), dts(i)) where the
>compiler said it needed a type for the 2nd dts(i), so I
am
>kind of in an infinite loop here. Could anyone suggest
>what kind of collection object/structure I could use to
>loop through the 4 different classes?
>
>Thanks,
>Ron
>.
>



Relevant Pages

  • Re: A Faster/Better way?
    ... compiler and library. ... The implied do loop above ... OTOH by reading array slices like the ... descriptor (a modified descriptor describing the slice, ...
    (comp.lang.fortran)
  • Re: How to use Arrays that are not Evil
    ... array over the vector... ... loop, then simply increments it in inner loop. ... I can only conclude that the STL vector code gives the compiler more ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Why Lisp supposedly "sucks for game development"
    ... I've always had this question about array ... > always resulted in an application of AREF within the body of the loop ... > declarations and enough knowledge about the array in question). ... might it take to tell the compiler that a form is to be executed ...
    (comp.lang.lisp)
  • Re: Sun Studio Express 3 compilers available for download
    ... array expression. ... loop unrolling is often the best choice. ... But, the compiler ... temporaries more or less doubles execution times. ...
    (comp.lang.fortran)
  • Re: help executing a list
    ... > in a loop, ... The compiler can only be invoked at run-time by calling one of these ... (defmethod vector+ ((a number) ... the class VECTOR is defined as a single-dimension array. ...
    (comp.lang.lisp)