CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 58

Threaded View

  1. #33
    Join Date
    Jan 2010
    Posts
    32

    Re: Display highlighted data from Listbox in Textboxes

    thanks. Yes, the code has no errors, it compiles, and it works pretty much. The reason I am storing the structures into an array is because that's what the directions ask for. Basically, I want each contact to be a structure that is then stored into an array with a maximum number of contacts of 20. Here is the exact problem in the book:

    Write a Windows Application that maintains an address book. This address book should hold up to 20 entries. You must store your data with arrays. Each address entry will have the following:

    •Last Name, First Name
    •Street Address
    •City
    •State
    •Zip Code


    Your program must have the following functionality:

    •Display the address book (names only in alphabetical order by last name)
    •Display all information about an individual entry (allow the user to select this)
    •Add address entry
    •Delete address entry


    Here is the updated code:

    Code:
    public struct Contacts
    {
                public string FirstName;
                public string LastName;
                public string Street;
                public string City;
                public string State;
                public string Zip;
    
    }           Contacts [] arrayOfContacts = new Contacts [20];
    
                private void btnExit_Click(object sender, EventArgs e)
                {
                    // Close program
                    this.Close();
                }
    
                private void btnAdd_Click(object sender, EventArgs e)
                {
                    // Declare variables
                    Contacts entry;
                    entry.FirstName = tbxFirstName.Text;
                    entry.LastName = tbxLastName.Text;
                    entry.Street = tbxStreet.Text;
                    entry.City = tbxCity.Text;
                    entry.State = tbxState.Text;
                    entry.Zip = tbxZip.Text;
    
                    // Add contact to array
                    arrayOfContacts[0] = entry;
                    
                    // Display Contacts (First and Last name only) in Listbox
                    lstContacts.Items.Add(entry.LastName + ", " + entry.FirstName);
    
                    // Clear Text Boxes
                    tbxFirstName.Text = "";
                    tbxLastName.Text = "";
                    tbxStreet.Text = "";
                    tbxCity.Text = "";
                    tbxState.Text = "";
                    tbxZip.Text = "";
    
                } 
    
           
        }
    }
    So, now this structure created by clicking the "Add" button is added to the array as element "0", correct?
    Last edited by CarlMartin; January 25th, 2010 at 08:54 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured