Still need help, arrays.

Page 1 of 1

3 Replies - 216 Views - Last Post: 22 October 2013 - 07:49 PM Rate Topic: -----

#1 delina  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-October 13

Still need help, arrays.

Posted 22 October 2013 - 07:08 PM

Hello everyone,

I need some help. I am working in a Windows Form application in C# in Microsoft Visual Studio. I posted this earlier, but I still can't figure it out.

I have created 3 labels.
I have created 2 buttons.
The first button called button1 is the button to add a contact.
The second button called button2 is the button that refreshes the list box.
I have created 1 list box called listBox1
I have created 2 textboxes
The first is called nameTextBox
The second is called emailTextBox
All of these are located on a form called form1

My application is supposed to get input from the user (name and email). The user click Add Contact button and the information saves to a .txt file. My code does this fine so far. Then, the user clicks the Refresh button and the list box is supposed to show all the information in the .txt file. This is where I run into a problem. I know that the problem is in my array. I have tried everything that I could think of and that I was told to try, but I am stuck.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Lab7A
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }

        private void nameLabel_Click(object sender, EventArgs e)
        {

        }

        private void nameTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void emailLabel_Click(object sender, EventArgs e)
        {

        }

        private void emailTextBox_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string name, email;

            try
            {
                using (StreamWriter storeInfo = new StreamWriter("info.txt", true))
                {
                    name = nameTextBox.Text;
                    email = emailTextBox.Text;

                    storeInfo.WriteLine(name + "|" + email);
                    this.button1.Visible = true;
                    nameTextBox.Text = string.Empty;
                    emailTextBox.Text = string.Empty;
                }
            }
            catch (System.IO.IOException exc)
            {
                MessageBox.Show("Error!\n" + exc.Message);
            }
        }

        private void contactsLabel_Click(object sender, EventArgs e)
        {

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string info;
            string [ ] recordData = new string [2];
            string cname = string.Empty;
            string cemail = string.Empty;
            string outInfo = string.Empty;;

            try
            {
                using (StreamReader getInfo = new StreamReader("info.txt"))
                {
                    listBox1.Items.Clear();
                    while (!getInfo.EndOfStream)
                    {
                        info = getInfo.ReadLine();
                        recordData = info.Split ('|');
                        outInfo = recordData[0] + "     " +
                            String.Format("{0:c}", double.Parse(recordData[0]));
                        listBox1.Items.Add(outInfo);
                    }
                    
                    listBox1.Visible = true;

                }
            }
            catch (System.IO.IOException exc)
            {
                listBox1.Text = exc.Message;
            }
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Still need help, arrays.

#2 h4nnib4l  Icon User is online

  • The Noid
  • member icon

Reputation: 1175
  • View blog
  • Posts: 1,661
  • Joined: 24-August 11

Re: Still need help, arrays.

Posted 22 October 2013 - 07:43 PM

Okay, so what are you stuck with? What happens when you step into the event handler that is supposed to read from the text file and display it? Do you know how to use your debugger?
Was This Post Helpful? 0
  • +
  • -

#3 delina  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 13-October 13

Re: Still need help, arrays.

Posted 22 October 2013 - 07:49 PM

View Posth4nnib4l, on 22 October 2013 - 07:43 PM, said:

Okay, so what are you stuck with? What happens when you step into the event handler that is supposed to read from the text file and display it? Do you know how to use your debugger?


I checked the .txt file and my information is saving to it just fine. What I am stuck on is getting that same information and displaying it in the list box. I was using an example so I created a retrieve (button2) button. It was supposed to make things easier. The thing is that when I click button2 nothing happens. I can't make the information show up in the list box.

I used the start debugging option (F5).
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10184
  • View blog
  • Posts: 37,599
  • Joined: 27-December 08

Re: Still need help, arrays.

Posted 22 October 2013 - 07:49 PM

Please avoid duplicate posting, especially since your other thread is still active.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1