Click here to Skip to main content
15,886,756 members
Home / Discussions / C#
   

C#

 
GeneralRe: graphics Pin
cshivaprasad1-May-06 21:19
cshivaprasad1-May-06 21:19 
GeneralRe: graphics Pin
CWIZO1-May-06 21:23
CWIZO1-May-06 21:23 
GeneralRe: graphics Pin
cshivaprasad1-May-06 21:32
cshivaprasad1-May-06 21:32 
GeneralRe: graphics Pin
CWIZO1-May-06 21:35
CWIZO1-May-06 21:35 
GeneralRe: graphics Pin
cshivaprasad1-May-06 23:41
cshivaprasad1-May-06 23:41 
GeneralRe: graphics Pin
CWIZO1-May-06 23:45
CWIZO1-May-06 23:45 
GeneralRe: graphics Pin
cshivaprasad2-May-06 0:08
cshivaprasad2-May-06 0:08 
QuestionDerived CollectionBase Class overwriting previous entries. Pin
Steven_Henley1-May-06 20:24
Steven_Henley1-May-06 20:24 
Hello,

I am stuck on a Collection class in which my code is apparently overwriting the previous entries whenever an 'Add' is performed. I imagine I am overlooking something or implementing something incorrectly, but I have been unable to locate my problem. Any assistance will be greatly appreciated.

Note that I fealt this was a problem with the instantiation of the item contained within the collection class, but I create a new instantiation within the while loop. Additionally, I have tried this from outside the class and within the class. The class is to determine the email addresses and group names contained within a comma-delimited string of text ( in this case the txt_To.Text ).

The code that I feel to be relevant ( though it may be too much ) is as follows:

Collection Class code:

using System;
using System.IO;
using System.Collections;

namespace Direct_Mailer.Classes
{
	public class Address_List : CollectionBase
	{
        private static string
            _Name = null;

		public Address_List()
		{
		}

        public Address_List( string Name )
        {
            _Name = Name;
        }


        #region Address List Methods

        #region Standard Methods

        public Address this[ int index ]
        {
            get
            {
                return ( Address )List[ index ];
            }
            set
            {
                List[ index ] = value;
            }
        }

        public int Add( Address value )
        {
            try
            {
                return List.Add( value );
            }
            catch( Exception this_Exception )
            {
                throw new Exception( "Add to the Address List failed.", this_Exception );
            }
        }

        public void Insert( int index, Address value )
        {
            try
            {
                List.Insert( index, value );
            }
            catch( Exception this_Exception )
            {
                throw new Exception( "Insertion into the Address List failed.", this_Exception );
            }
        }

        public void Remove( Address value )
        {
            try
            {
                List.Remove( value );
            }
            catch( Exception this_Exception )
            {
                throw new Exception( "Removal from the Address List failed.", this_Exception );
            }
        }

        public int IndexOf( Address value )
        {
            try
            {
                return List.IndexOf( value );
            }
            catch( Exception this_Exception )
            {
                throw new Exception( "Attempt of IndexOf failed in Address List.", this_Exception );
            }
        }

        public void CopyTo( Address[] Address_Array, int index)
        {
            try
            {
                List.CopyTo( Address_Array, index );
            }
            catch( Exception this_Exception )
            {
                throw new Exception( "The CopyTo method failed in Address List.", this_Exception );
            }
        }

        #endregion

        #region Class Specific Methods

        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        static private Address this_Address = new Address();

        public Address_List generate_List( string comma_delim )
        {
            int begin_pos = 0,
                comma_pos   = 0,
                amp_pos   = 0;


            try
            {
                while( comma_pos >= 0 )
                {
                    comma_pos = comma_delim.IndexOf( ',', comma_pos );
                    if ( comma_pos <= 0 )
                        this_Address.address = comma_delim.Substring( begin_pos);
                    else
                        this_Address.address = comma_delim.Substring( begin_pos, comma_pos - begin_pos );
                    this_Address.address.Trim();

                    amp_pos = this_Address.address.IndexOf( '@' );
                    if ( amp_pos != -1 )
                        this_Address.type = Address.Type.Address;
                    else
                        this_Address.type = Address.Type.Group;

                    List.Add( this_Address );
                    
                    if ( comma_pos >= 0 )
                        begin_pos = amp_pos = ++comma_pos;
                }
                return this;
            }
            catch( Exception this_Exception )
            {
                throw new Exception( "Error occured attempting to generate an Address List.", this_Exception );
            }
        }

        #endregion

        #endregion
	}
}



From the item class the Collection class contains:

using System;
using System.IO;

namespace Direct_Mailer.Classes
{
	public class Address
	{
		public Address()
		{
		}

        public enum Type
            { Address, Group };

        private static string
            _address = null;

        public string address
        {
            get
            {
                return _address;
            }
            set
            {
                _address = value;
            }
        }

        private static Type _type = 0;

        public Type type
        {
            get
            {
                return _type;
            }
            set
            {
                _type = value;
            }
        }
	}
}



From the function on the form that accesses the collection:

private void btn_Send_Click(object sender, System.EventArgs e)
{
    Address_List To_List = new Address_List();

    if ( txt_To.Text.Length <= 0 )
    {
        MessageBox.Show("This email has not been addressed to anyone", "Direct Mailer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation );
        txt_To.BackColor = Color.LightCoral;
        return;
    }

    To_List.generate_List( txt_To.Text );

    txt_Body.Text = "Listing produced the following:";
    for ( int counter = 0; counter < To_List.Count; counter++ )
    {
        txt_Body.Text += "\n\t" + To_List[ counter ].address
            + "\t" + To_List[ counter ].type.ToString();
    }
}


Far better to keep one's mouth shut
_ and appear stupid

than to open one's mouth
_ and remove all doubt.

I rarely follow this.
QuestionWebBrowser / HtmlElement Class Help Pin
joetoday1-May-06 19:32
joetoday1-May-06 19:32 
AnswerRe: WebBrowser / HtmlElement Class Help Pin
leppie1-May-06 20:25
leppie1-May-06 20:25 
GeneralRe: WebBrowser / HtmlElement Class Help Pin
joetoday2-May-06 11:35
joetoday2-May-06 11:35 
Questionreading a file in C# Pin
leanhsang1-May-06 17:36
leanhsang1-May-06 17:36 
AnswerRe: reading a file in C# Pin
CWIZO1-May-06 21:23
CWIZO1-May-06 21:23 
AnswerRe: reading a file in C# Pin
stancrm1-May-06 23:21
stancrm1-May-06 23:21 
QuestionDocument Properties Pin
smarttom991-May-06 17:16
smarttom991-May-06 17:16 
QuestionRecommendation Pin
John L. DeVito1-May-06 15:05
professionalJohn L. DeVito1-May-06 15:05 
AnswerRe: Recommendation Pin
Michael A. Barnhart1-May-06 15:17
Michael A. Barnhart1-May-06 15:17 
AnswerRe: Recommendation Pin
Al Ortega1-May-06 15:56
Al Ortega1-May-06 15:56 
AnswerRe: Recommendation Pin
Joe Woodbury1-May-06 18:14
professionalJoe Woodbury1-May-06 18:14 
QuestionChanging Order of Items in a Bound ListBox Pin
myNameIsRon1-May-06 12:25
myNameIsRon1-May-06 12:25 
AnswerRe: Changing Order of Items in a Bound ListBox Pin
Josh Smith2-May-06 1:30
Josh Smith2-May-06 1:30 
GeneralRe: Changing Order of Items in a Bound ListBox Pin
myNameIsRon2-May-06 16:05
myNameIsRon2-May-06 16:05 
QuestionData Grid - Setting Current Column and arrow key capture Pin
Michael A. Barnhart1-May-06 12:15
Michael A. Barnhart1-May-06 12:15 
QuestionDLL question Pin
Tom Wright1-May-06 12:12
Tom Wright1-May-06 12:12 
AnswerRe: DLL question Pin
Robin Panther1-May-06 13:07
Robin Panther1-May-06 13:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.