Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP Classes: How do I iterate through a property that's an array?

Reply
Thread Tools

ASP Classes: How do I iterate through a property that's an array?

 
 
Guest
Posts: n/a
 
      04-18-2005

I'm going a little crazy trying to learn how to use arrays as properties in
VBScript classes. Hopefully someone can help. First, I can't figure out
whether it's possible to iterate through the members of an array that I have
assigned to a propety. Second, I'm finding the question of "Property Let"
versus "Property Set" to be very confusing.

I have this code that utilizes a custom class I've defined, called clsGroup:

myString = ", ,
"

Dim objGroup
Set objGroup = New clsGroup
objGroup.EmailsAsArray = ParseCommaDelimitedStringToArray(myString)

If I test the resulting array, as follows:
Response.Write(IsArray(objGroup.EmailsAsArray))
....it resolves to "True". So objGroup.EmailsAsArray is successfully assigned
an array, which is what I want.

Confusing things:

1) If I try a simple loop, as follows...

dim myThingy
For each myThingy in objGroup.EmailsAsArray
response.write myThingy & "<br>"
Next

....this doesn't work. It complains that I'm not dealing with a collection.
This makes some sense, because I have a collection wrapped up in an object.
What's the right practice and/or syntax in this case?

2) The second thing that has me confused is whether an array is an object or
not. I'm thinking it is not. I wasted a lot of time trying to use the
"Property Set" declaration in trying to assign the array to my
..EmailsAsArray property. In the end, the only thing that would not return an
error was the more typical "Get/Let" pair:

Public Property Get EmailsAsArray()
EmailsAsArray = m_objEmailsAsArray
End Property
Public Property Let EmailsAsArray(objEmailsAsArray)
m_objEmailsAsArray = objEmailsAsArray
End Property

The amount of literature devoted to Class development in classic ASP is
unimpressive. Maybe time to move on up to ASP.NET.

Any help out there?

-KF


 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      04-18-2005
wrote:
> I'm going a little crazy trying to learn how to use arrays as
> properties in VBScript classes. Hopefully someone can help. First, I
> can't figure out whether it's possible to iterate through the members
> of an array that I have assigned to a propety. Second, I'm finding
> the question of "Property Let" versus "Property Set" to be very
> confusing.
>
> I have this code that utilizes a custom class I've defined, called
> clsGroup:
>
> myString = ", ,
> "
>
> Dim objGroup
> Set objGroup = New clsGroup
> objGroup.EmailsAsArray = ParseCommaDelimitedStringToArray(myString)


What is this "Parse..." thingy? Did you reinvent the builtin split() method?

>
> If I test the resulting array, as follows:
> Response.Write(IsArray(objGroup.EmailsAsArray))
> ...it resolves to "True". So objGroup.EmailsAsArray is successfully
> assigned an array, which is what I want.
>
> Confusing things:
>
> 1) If I try a simple loop, as follows...
>
> dim myThingy
> For each myThingy in objGroup.EmailsAsArray
> response.write myThingy & "<br>"
> Next
>
> ...this doesn't work. It complains that I'm not dealing with a
> collection. This makes some sense, because I have a collection
> wrapped up in an object. What's the right practice and/or syntax in
> this case?


Hmm, according to the docs, a "for each" loop should work with an array. In
fact, this works fine:

dim ar, i
ar=array(14,2,3)
for each i in ar
response.write i & "<BR>"
next


Have you tried a simple "for i = 0 to ubound(...)" loop?


>
> 2) The second thing that has me confused is whether an array is an
> object or not. I'm thinking it is not.


Correct. You never use Set with arrays in vbscript.

You can download the vbscript documentation from:
http://tinyurl.com/7rk6

Bob Barrows
PS. This isn't really an asp question: it's more of a vbscript question. The
vbscript gurus hang out at m.p.scripting.vbscript.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Iterate through ASP.Net Ajax Tab Container ? Luqman ASP .Net 2 04-27-2008 06:55 AM
How to iterate 2 nested collections w <logic:iterate> without a"getter" John Java 4 04-01-2008 09:46 AM
nested:iterate or logic: iterate with multibox?? runescience Java 0 02-09-2006 12:57 AM
<logic:iterate /> iterate beyond items in the collection Gogo Java 1 09-04-2003 08:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57