473,387 Members | 1,353 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,387 software developers and data experts.

collection list count (CollectionBase) list.add - problems

Hello. I've got this simple collection populate code I downloaded from
the net (sorry can't find source now) I'm trying to test, but I can't
seem to get it to work. Any help would be greatly appreciated.

I've compiled the following VB.NET into a DLL:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections

Namespace jcpcollection

Public Class Users
Inherits CollectionBase

'Retrieves an item from the collection by index
Default Public Property Item(ByVal Index As Integer) As User
Return CType(list.Item(Index), User)
End Get
Set(ByVal Value As User)
list.Item(Index) = Value
End Set
End Property

'Adds an item to the collection
Public Function Addx(ByVal Item As User) As Integer
Return list.Add(Item)
End Function
'test function
Public Function test As Integer
dim z as integer
return z
End Function
'Reports Total
Public Function totalentries As Integer
Return list.Count
End Function

Public Sub Remove(ByVal Item As User)
End Sub

'A function that checks the length of the email address , applied to
very member of the collection
Public Shared Function ValidateEmail(ByVal emailAddress As String)
If Not (emailAddress.Length > 0) Then Throw New
ArgumentException("Please provide a valid email address")
End Function

End Class 'Users Collection - strongly typed IList collection of User
Public Class User

#Region "Attributes"

'Internal storage for the UserName property
Protected _UserName As String = Nothing

'The user name of the user
Public Property UserName() As String
Return Me._UserName
End Get
Set(ByVal Value As String)
Me._UserName = Value
End Set
End Property

'Internal storage for the EmailAddress property
Protected _EmailAddress As String = Nothing

'Gets / Sets the EmailAddress of the User
Public Property EmailAddress() As String
Return Me._EmailAddress
End Get
Set(ByVal Value As String)
Me._EmailAddress = Value
End Set
End Property

#End Region
#Region "Constructors/Destructors"

'A constructor that accepts a DataTable
Public Sub New(ByVal table As DataTable)

If table.Rows.Count > 0 Then

Dim row As DataRow

row = table.Rows(0)

'run the loop once because only one row can be matched to a member of
a collection
Me._EmailAddress = row("EmailAddress")

Me._UserName = row("UserName")

End If

End Sub

'Another constructor for initializing each member of the collection
Public Sub New(ByVal nEmailAddress As String, ByVal nUserName As

Me._EmailAddress = nEmailAddress
Me._UserName = nUserName

End Sub
#End Region
#Region "Functions/Procedures/Operations"

#End Region

End Class 'User Class

End Namespace

And here the ASP.NET (VB) I'm using to test it with:

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Diagnostics"%>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Web.Mail"%>
<%@ Import Namespace="System" %>
<%@ Import Namespace="jcpcollection" %>

<body text=#336633 bgcolor=#CCAA99>

<basefont size="2" font face="Veranda" color="#000000">

<form method="post" runat="server">

<asp:label id="mylabel" runat="server"/>
<asp:textbox value="" runat="server" id="userin"
Rows="1" Width="200"/>

<asp:textbox value="" runat="server" id="emailin"
Rows="1" Width="200"/>
<asp:Button ID="submit" Text="Insert" Runat="server" onclick=testit


<script language="VB" runat="server">
Sub Page_Load(Src as object, E as EventArgs )

'display total entries in collect here next

Dim nUsers As New Users
Dim nUser As User
dim howmany as integer
howmany = nUsers.totalentries
howmany = nUsers.test

end sub

sub testit(Src as object, E as EventArgs)

Dim nUsers As New Users
Dim nUser As User
nUser = New User(emailin.text,userin.text)
dim xx as integer
xx = nUsers.Addx(nUser)
response.write("<br>"+ nUser.username+"<br>"+ nUser.EmailAddress)
end sub


When I press 'Insert' I don't see an updated count . I'm also getting
a return code of 1 for ADDX.

What's wrong? Other than my not know what the hell I'm doing - New to
VB here.
Nov 17 '05 #1
3 4569

Can't see the declaration of list. did you miss somthing ?

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2
Thanks for response.

I think I figured out my problem. It was more conceptual than
anything else.

The collection is *always* recreated at postback and I was attempting
to get a list count in the page_load of the asp.net, so naturally, I
had a count of zero. The code was just an experiment to better
understand vb.net collections.

If I add a bunch of .addx(xxx,yyy) in the page_load and then get the
count I do see the collection is populated. Though I gotta wonder,
what the point is in using collections in web ap, when you need to
store that info with some permanence somewhere anyways?

All: Why use collections in Web aps? And not just store the info in db
or flat file?
Nov 17 '05 #3

Retrieving data from memory is more efficient that from file or DB. But
storing too much data on memory can cause memory caching on disk causing
worse performance problem.

Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #4

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

Similar topics

by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a...
by: Mart | last post by:
What class does everyone out there use if they want to store a set of values efficiently? In java I use a HashSet, but there is no equivalent in C#. Even worse, the lowest level interface to...
by: Gary | last post by:
I would like to make a strongly typed, sortable collection by leveraging a Framework class. I began by looking at CollectionBase but it doesn't have built-int sorting. I would prefer to derive...
by: songie D | last post by:
If you remove an item from a collection (that is derived from CollectionBase and thus implements IList will the index property automatically 'shuffle' up one i.e. if of {0, 1, 2, 3} I delete item...
by: Jannik Anker | last post by:
I have a standard CollectionBase implementation called UnitCollection. And yes, the collection items are class Unit ;-) Code: public class Row { public Row() { ... }
by: Michael K. Walter | last post by:
I'd like to create a strongly-typed collection of objects that are indexed by a string value (key is a string). I'd also like to allow users to iterate over the collection using a For-each loop...
by: Ruben | last post by:
I have a collection (PersonCollection inherits collectionbase and implements ITypedList it's a collection of Person objects) this collection also implements the IComponent interface, so I can drag...
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
by: Řyvind Isaksen | last post by:
I try to make my own ArticleAttribute object and ArticleAttributeCollection, and add data to this Collection. It almost works, but the problem is that each time I add an ArticleAttribute to my...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
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...
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,...
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...
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...

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.