Hi, Folks!

Let say I have a class like:

Class clsMyClass
Public iNumber
Public szQuestion
Public szResponse
End Class

How can I extend this:
Dim myTest : Set myTest = New clsMyClass

...into an array?

Would it be like:
Dim myTest(2) : Set myTest = Array(New clsMyClass, New clsMyClass, New
clsMyClass)

How could you do this dynamically?

TIA...

Re: Newbie Question: Classes and Arrays by mayayana

mayayana
Tue Jan 30 00:23:24 CST 2007

Wouldn't it make more sense to put arrays in
the class? A class doesn't serve much purpose unless
it helps to organize the code better. If the 3 variables
in the class were arrays then you'd only need one
class and you could do:

i = Class1.iNumber(3)

You'd just need to have 2 parameters in your Let
property and 1 parameter in your Get property.
Then redim your array when a new number is added.


> Let say I have a class like:
>
> Class clsMyClass
> Public iNumber
> Public szQuestion
> Public szResponse
> End Class
>
> How can I extend this:
> Dim myTest : Set myTest = New clsMyClass
>
> ...into an array?
>
> Would it be like:
> Dim myTest(2) : Set myTest = Array(New clsMyClass, New clsMyClass, New
> clsMyClass)
>
> How could you do this dynamically?
>
> TIA...
>



Re: Newbie Question: Classes and Arrays by Al

Al
Tue Jan 30 00:28:23 CST 2007


"Blue Streak" <rdlebreton@hotmail.com> wrote in message
news:1170114587.061293.33060@v45g2000cwv.googlegroups.com...
> Hi, Folks!
>
> Let say I have a class like:
>
> Class clsMyClass
> Public iNumber
> Public szQuestion
> Public szResponse
> End Class
>
> How can I extend this:
> Dim myTest : Set myTest = New clsMyClass
>
> ...into an array?
>
> Would it be like:
> Dim myTest(2) : Set myTest = Array(New clsMyClass, New clsMyClass, New
> clsMyClass)
>
> How could you do this dynamically?

The above is a type mismatch, as the array function returns an array rather
than the object that is expect by the SET statement. If you explicitly
DIMension your array, I think you would need to assign object values to each
element like this:

myTest(0) = new clsMyClass
myTest(1) = new clsMyClass
myTest(2) = new clsMyClass

or in a loop.

If you want the simplicity of using the Array function, just lost the
dimension from the DIM statement and lost the SET:

dim myTest : myTest = Array(New clsMyClass, New clsMyClass, New
clsMyClass)

/Al



Re: Newbie Question: Classes and Arrays by Blue

Blue
Tue Jan 30 14:12:08 CST 2007

On Jan 30, 1:28 am, "Al Dunbar [MS-MVP]" <alan-no-drub-
s...@hotmail.com> wrote:
> "Blue Streak" <rdlebre...@hotmail.com> wrote in message
>
> news:1170114587.061293.33060@v45g2000cwv.googlegroups.com...
>
>
>
>
>
> > Hi, Folks!
>
> > Let say I have a class like:
>
> > Class clsMyClass
> > Public iNumber
> > Public szQuestion
> > Public szResponse
> > End Class
>
> > How can I extend this:
> > Dim myTest : Set myTest = New clsMyClass
>
> > ...into anarray?
>
> > Would it be like:
> > Dim myTest(2) : Set myTest =Array(New clsMyClass, New clsMyClass, New
> > clsMyClass)
>
> > How could you do this dynamically?
>
> The above is a type mismatch, as thearrayfunction returns anarrayrather
> than the object that is expect by the SET statement. If you explicitly
> DIMension yourarray, I think you would need to assign object values to each
> element like this:
>
> myTest(0) = new clsMyClass
> myTest(1) = new clsMyClass
> myTest(2) = new clsMyClass
>
> or in a loop.
>
> If you want the simplicity of using theArrayfunction, just lost the
> dimension from the DIM statement and lost the SET:
>
> dim myTest : myTest =Array(New clsMyClass, New clsMyClass, New
> clsMyClass)
>
> /Al- Hide quoted text -
>
> - Show quoted text -

I will try that, Thx

Obviously, this cannot be done dynamically.


Re: Newbie Question: Classes and Arrays by Bob

Bob
Tue Jan 30 14:27:08 CST 2007

Blue Streak wrote:
>
> Obviously, this cannot be done dynamically.

Explain what you mean by "dynamically".
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: Newbie Question: Classes and Arrays by Blue

Blue
Tue Jan 30 14:38:57 CST 2007

On Jan 30, 3:27 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
> Blue Streak wrote:
>
> > Obviously, this cannot be done dynamically.
>
> Explain what you mean by "dynamically".
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.

Dim myArray() 'denotes a dynamic array
...
Redim myArray(5) 'Resizes the array



Re: Newbie Question: Classes and Arrays by Blue

Blue
Tue Jan 30 14:51:49 CST 2007

On Jan 30, 3:27 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
> Blue Streak wrote:
>
> > Obviously, this cannot be done dynamically.
>
> Explain what you mean by "dynamically".
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.

Ugh! Never mind!

I just discovered this DOES work dymanically...

:P



Re: Newbie Question: Classes and Arrays by Blue

Blue
Tue Jan 30 15:38:12 CST 2007

On Jan 30, 3:51 pm, "Blue Streak" <rdlebre...@hotmail.com> wrote:
> On Jan 30, 3:27 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
> wrote:
>
> > Blue Streak wrote:
>
> > > Obviously, this cannot be done dynamically.
>
> > Explain what you mean by "dynamically".
> > --
> > Microsoft MVP -- ASP/ASP.NET
> > Please reply to the newsgroup. The email account listed in my From
> > header is my spam trap, so I don't check it very often. You will get a
> > quicker response by posting to the newsgroup.
>
> Ugh! Never mind!
>
> I just discovered this DOES work dymanically...
>
> :P

Just to add to my own post and the reference of others this works.
Obviously, I'm doing more by reading in an XML document.

=====================
Class clsMyClass
Public iNumber
Public szQuestion
Public szResponse
End Class

Dim myTest()
...
Redim myTest(oXML.getElementsByTagName("...").length - 1)

For i=0 To (oXML.getElementsByTagName("...").length - 1)
Set myTest(i) = New clsMyClass '
Next

...

i = 0
For Each oElement In oXML.getElementsByTagName("...")
myTest(i).iNumber = oElement.childNode(0).text
myTest(i).szQuestion = oElement.childNode(1).text
...
Next

etc...
=====================

Thanks!


Re: Newbie Question: Classes and Arrays by Blue

Blue
Tue Jan 30 15:51:26 CST 2007

On Jan 30, 4:38 pm, "Blue Streak" <rdlebre...@hotmail.com> wrote:
> On Jan 30, 3:51 pm, "Blue Streak" <rdlebre...@hotmail.com> wrote:
>
>
>
>
>
> > On Jan 30, 3:27 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
> > wrote:
>
> > > Blue Streak wrote:
>
> > > > Obviously, this cannot be done dynamically.
>
> > > Explain what you mean by "dynamically".
> > > --
> > > Microsoft MVP -- ASP/ASP.NET
> > > Please reply to the newsgroup. The email account listed in my From
> > > header is my spam trap, so I don't check it very often. You will get a
> > > quicker response by posting to the newsgroup.
>
> > Ugh! Never mind!
>
> > I just discovered this DOES work dymanically...
>
> > :P
>
> Just to add to my own post and the reference of others this works.
> Obviously, I'm doing more by reading in an XML document.
>
> =====================
> Class clsMyClass
> Public iNumber
> Public szQuestion
> Public szResponse
> End Class
>
> Dim myTest()
> ...
> Redim myTest(oXML.getElementsByTagName("...").length - 1)
>
> For i=0 To (oXML.getElementsByTagName("...").length - 1)
> Set myTest(i) = New clsMyClass '
> Next
>
> ...
>
> i = 0
> For Each oElement In oXML.getElementsByTagName("...")
> myTest(i).iNumber = oElement.childNode(0).text
> myTest(i).szQuestion = oElement.childNode(1).text
> ...
> Next
>
> etc...
> =====================
>
> Thanks!- Hide quoted text -
>
> - Show quoted text -

Oh, God!

I forgot the line:

i = 0
For Each oElement In oXML.getElementsByTagName("...")
myTest(i).iNumber = oElement.childNode(0).text
myTest(i).szQuestion = oElement.childNode(1).text
...
i = i + 1
Next