Results 1 to 5 of 5

Thread: need help with this C# .net app

  1. #1
    Join Date
    Feb 2009
    Posts
    96

    need help with this C# .net app

    Code:
    int itemCount;
            public struct addressBook
            {
                public string lastName;
                public string firstName;
                public string street;
                public string city;
                public string state;
                public int zip;
            }
            addressBook[] book = new addressBook[20];
     
            public MainForm()
            {
                InitializeComponent();
            }
    
    private void btnAdd_Click(object sender, EventArgs e)
            {
               
                    
                    string wholeName = "";
                    try
                    {
                       // if (lstDisplay.SelectedIndex != 0)
                       // {
                            book[itemCount].lastName = txtLast.Text;
                            book[itemCount].firstName = txtFirst.Text;
                            book[itemCount].street = txtStreet.Text;
                            book[itemCount].city = txtCity.Text;
                            book[itemCount].state = txtState.Text;
                            book[itemCount].zip = int.Parse(mTxtZip.Text);
    
                            itemCount++;
                            clear();
                          //  lbltest.Text = book[itemCount].ToString();
                        //}
                         
                       // else
                       // {
                        //    MessageBox.Show("ERROR!!\n" + "Check your input.");
                       // }
                    }
                    catch (FormatException)
                    {
                        MessageBox.Show("ERROR!!\n" + "Check your input.");
                    }
            
                    for (int i = 0; i < book.Length; i++)
                    {
                        wholeName = book[i] + "\n" + wholeName  ;
                       
                    }
                    lstDisplay.Text = wholeName; //book[itemCount].lastName + " , " + book[itemCount].firstName;
                    lbltest.Text = wholeName;
            }
    what i want is when the user enters the info in text boxes for that info to be stored into an array then the last name, first name to be shown up in the listtextbox but all i get now is nothing. Any help would be appreciated. lstDisplay.Text is my list text box

  2. #2
    Join Date
    May 2008
    Posts
    685

    Re: need help with this C# .net app

    Hello Daren, there is very small mistake in your code but it is the most important part of your code. You have not assigned any value to your "itemCount" variable and this is the main reason why you are not getting the correct/no output.

  3. #3
    Join Date
    Nov 2005
    Posts
    1,187

    Re: need help with this C# .net app

    Hi
    for (int i = 0; i < book.Length; i++)
    {
    wholeName = book[i] + "\n" + wholeName ;

    }
    I think the for loop is incomplete. You have not printed the value of array. I think if you have to print the value of the array then you have to include the following statement in the for loop.
    lstDisplay.Text = wholeName; //book[itemCount].lastName + " , " + book[itemCount].firstName;

  4. #4
    Join Date
    Feb 2009
    Posts
    96

    Re: need help with this C# .net app

    i get this showing up -- the list box is empty as you can see and the test lable prints out crap


  5. #5
    Join Date
    Feb 2009
    Posts
    96

    Re: need help with this C# .net app



    this is what i get any ideas on how to fix this?

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,707,927.77564 seconds with 15 queries