473,396 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Classes and collections in ASP?

I've always had problems getting my head around using collections and
classes together. Separately, they seem like fairly simple subjects, but I'm
getting muddled up when trying to use them together.

Even trying to cobble together an example to post here with my question has
me confused.

Can someone toss together a simple example of how I'd create my classes and
collection?

What I was going to use was...

Class "cName" with properties of "First" and "Last"
Class "cMovie" with properties of "Title" and "Year"
Class "cActor" with properties of a "cName" and a collection of "cMovie"'s

So in my code I'd do...

<%

Dim Actor
Set Actor = New cActor

Actor.FirstName = "Pierce"
Actor.LastName = "Brosnan"
Actor.Movies.Add "Tomorrow Never Dies","1997"
Actor.Movies.Add "GoldenEye","1995"
Actor.Movies.Add "The World is Not Enough", "1999"

response.write "Actor: " & Actor.FirstName & " " & Actor.Lastname & "<br>"
response.write "Films: <br>"

Dim Film

for each Film in Actor.Movies
response.write Film.Title & " in " & Film.Year & " <br>"
next

%>


Feb 4 '06 #1
2 1315
It's not actually possible to build collection classes that support For Each
in VBScript
In fact VBScript doesn't even have a standard Collection object like VB6,
the closest thing is the Scripting.Dictionary but that's an annoying object
to use.

The following is the probably the nearest you can get to it in script:-

<%
Option Explicit

Dim Actor
Dim Film
Dim i

Set Actor = New CActor

Actor.FirstName = "Pierce"
Actor.LastName = "Brosnan"
Actor.Movies.Add "Tomorrow Never Dies","1997"
Actor.Movies.Add "GoldenEye","1995"
Actor.Movies.Add "The World is Not Enough", "1999"

For i = 1 To Actor.Movies.Count
Set Film = Actor.Movies.Item(i)
Response.Write Film.Title & " in " & Film.Year & "<br />"
Next

Class CActor
Public FirstName
Public LastName
Private moMovies

Public Property Get Movies()
Set Movies = moMovies
End Property

Private Sub Class_Initialize()
Set moMovies = New CMovies
End Sub

End Class

Class CMovie
Public Title
Public Year
End Class

Class CMovies

Private maoMovie
Private mlCount

Private Sub Class_Initialize()
ReDim maoMovie(8)
End Sub

Public Function Add(rsTitle, rdatYear)
If UBound(maoMovie) = mlCount Then
ReDim Preserve maoMovie(mlCount * 2)
End If
mlCount = mlCount + 1
Set maoMovie(mlCount) = New CMovie
maoMovie(mlCount).Title = rsTitle
maoMovie(mlCount).Year = rdatYear
Set Add = maoMovie(mlCount)
End Function

Public Property Get Count()
Count = mlCount
End Property

Public Default Property Get Item(Index)
Set Item = maoMovie(Index)
End Property

End Class
%>

Feb 4 '06 #2
Thanks for the excellent example!

Arrays work for me. Had me scratching my head for a minute at the "Set Add =
maoMovie(mlCount)" line in the Add function. Makes perfect sense now.

Thanks again!

"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:uR*************@TK2MSFTNGP12.phx.gbl...
It's not actually possible to build collection classes that support For
Each
in VBScript
In fact VBScript doesn't even have a standard Collection object like VB6,
the closest thing is the Scripting.Dictionary but that's an annoying
object
to use.

The following is the probably the nearest you can get to it in script:-

<%
Option Explicit

Dim Actor
Dim Film
Dim i

Set Actor = New CActor

Actor.FirstName = "Pierce"
Actor.LastName = "Brosnan"
Actor.Movies.Add "Tomorrow Never Dies","1997"
Actor.Movies.Add "GoldenEye","1995"
Actor.Movies.Add "The World is Not Enough", "1999"

For i = 1 To Actor.Movies.Count
Set Film = Actor.Movies.Item(i)
Response.Write Film.Title & " in " & Film.Year & "<br />"
Next

Class CActor
Public FirstName
Public LastName
Private moMovies

Public Property Get Movies()
Set Movies = moMovies
End Property

Private Sub Class_Initialize()
Set moMovies = New CMovies
End Sub

End Class

Class CMovie
Public Title
Public Year
End Class

Class CMovies

Private maoMovie
Private mlCount

Private Sub Class_Initialize()
ReDim maoMovie(8)
End Sub

Public Function Add(rsTitle, rdatYear)
If UBound(maoMovie) = mlCount Then
ReDim Preserve maoMovie(mlCount * 2)
End If
mlCount = mlCount + 1
Set maoMovie(mlCount) = New CMovie
maoMovie(mlCount).Title = rsTitle
maoMovie(mlCount).Year = rdatYear
Set Add = maoMovie(mlCount)
End Function

Public Property Get Count()
Count = mlCount
End Property

Public Default Property Get Item(Index)
Set Item = maoMovie(Index)
End Property

End Class
%>

Feb 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: toki | last post by:
public class Form1 : System.Windows.Forms.Form { MyClass myclass; public Form1() { myclass = new MyClass(); } }
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
12
by: Wes McCaslin | last post by:
I have a question about concrete and abstract classes. what are the differances? can you explain them to me. I have started an advance Visual Studio.Net class and I am having a hard time...
3
by: Paul | last post by:
Hello, I'm upgrading a small single user app to VB.NET and have a few questions about loading classes & collections classes with the data from a one to many dataset structure. I'm serializing...
1
by: Raju Joseph | last post by:
Hi All, We are in the process of developing an N-Tier app using VB.NET. We are extensively using classes (entity objects) in our design. Further, most of the times, we do have to specify nested...
3
by: Dave | last post by:
Please - anyone that can help. I am getting confusing results while trying to expose a collection from a web service. I have a webservice in which a web method accepts a collection as a...
5
by: M Harris | last post by:
We are developing an application (using .Net in MS Studio 2003 using the Access jet engine as a backend) that is doing quite a bit of number crunching. The first part of the application was...
4
by: Aidy | last post by:
In .net 1.1 we'd have a whole bunch of collections for each of our classes. So we'd have "ProductCollection", "UserCollection" etc etc, each a strongly-typed collection for that user. I know in...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.