Click here to Skip to main content
15,893,644 members
Home / Discussions / C#
   

C#

 
QuestionInt to string Pin
Rmokkenstorm1-May-06 21:35
Rmokkenstorm1-May-06 21:35 
AnswerRe: Int to string Pin
WillemM1-May-06 22:21
WillemM1-May-06 22:21 
GeneralRe: Int to string Pin
Rmokkenstorm1-May-06 22:25
Rmokkenstorm1-May-06 22:25 
AnswerRe: Int to string Pin
J4amieC1-May-06 23:22
J4amieC1-May-06 23:22 
AnswerRe: Int to string Pin
Guffa1-May-06 23:25
Guffa1-May-06 23:25 
GeneralRe: Int to string Pin
Rmokkenstorm1-May-06 23:38
Rmokkenstorm1-May-06 23:38 
AnswerRe: Int to string Pin
Josh Smith2-May-06 1:43
Josh Smith2-May-06 1:43 
GeneralRe: Int to string Pin
Rmokkenstorm2-May-06 2:43
Rmokkenstorm2-May-06 2:43 
GeneralRe: Int to string Pin
Josh Smith2-May-06 4:21
Josh Smith2-May-06 4:21 
GeneralRe: Int to string Pin
Rmokkenstorm2-May-06 4:34
Rmokkenstorm2-May-06 4:34 
Questionassigning Values to a resized string Array Pin
abhinish1-May-06 20:50
abhinish1-May-06 20:50 
AnswerRe: assigning Values to a resized string Array Pin
akyriako781-May-06 21:01
akyriako781-May-06 21:01 
Questiongraphics Pin
cshivaprasad1-May-06 20:42
cshivaprasad1-May-06 20:42 
AnswerRe: graphics Pin
CWIZO1-May-06 21:14
CWIZO1-May-06 21:14 
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 

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.