Click here to Skip to main content
15,917,702 members
Home / Discussions / C#
   

C#

 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 11:15
Henry Minute25-Mar-09 11:15 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
DaveyM6925-Mar-09 11:19
professionalDaveyM6925-Mar-09 11:19 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Luc Pattyn25-Mar-09 13:36
sitebuilderLuc Pattyn25-Mar-09 13:36 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Colin Angus Mackay25-Mar-09 14:48
Colin Angus Mackay25-Mar-09 14:48 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Wes Jones25-Mar-09 15:34
Wes Jones25-Mar-09 15:34 
AnswerRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
Henry Minute25-Mar-09 11:41
Henry Minute25-Mar-09 11:41 
GeneralRe: Anybody here handle what happens when you unplug a USB based Serial Port? Pin
DaveyM6925-Mar-09 11:43
professionalDaveyM6925-Mar-09 11:43 
QuestionStreamWriter help... Pin
VoodooInfinity25-Mar-09 10:07
VoodooInfinity25-Mar-09 10:07 
Okay, I've been trying to figure this out for the last 24 hours to no avail.

I'm writing a datebook style program just as a personal test while I learn, and I've run into a snag. The idea is that the user enters a date and event, then presses a 'save event' button which is supposed to both write the event to the event list window, and append it to a file called datebook.txt. My problem is that each time the 'save event' button is pressed, it rewrites the entire datebook.txt file. How do I fix this? I'm including the code below, minus irrelevant things (such as empty textChanged sections, etc).

Thanks.
namespace WpfApplication2
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            DateTime current = DateTime.Now;
            Entrance();
        }

        private void Entrance()
        {
            selectedDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
        }

        private void displayEvents_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DateTime selected = DateTime.Parse(enteredDate.Text);
                selectedDate.Text = selected.ToString("MM/dd/yyyy");
            }
            catch (FormatException)
            {
                MessageBox.Show("The date you enterd was invalid.\n\nPlease reenter the date in
 the format MM/dd/yyyy.");
            }
        }

        private void saveNewEvent_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                WriteToFile();
                WriteToEventList();
            }
            catch (FormatException)
            {
                MessageBox.Show("The date you enterd was invalid.\n\nPlease reenter the date in the format MM/dd/yyyy.");
            }
        }

        private void WriteToFile()
        {
            DateTime newEntry = DateTime.Parse(newDate.Text);
            string addEvent = "";
            addEvent = newEvent.Text;
            using (TextWriter writeEvent = new StreamWriter("datebook.txt"))
            {
                writeEvent.WriteLine(newEntry.ToString());
                writeEvent.WriteLine(addEvent); 
            }
        }

        private void WriteToEventList()
        {
            DateTime newEntry = DateTime.Parse(newDate.Text);
            string addEvent = "";
            addEvent = newEvent.Text;
            eventsList.AppendText(String.Format("{0}\t{1}\n", newEntry, addEvent));
        }
    }
}

AnswerRe: StreamWriter help... Pin
BOMBONEW25-Mar-09 10:14
BOMBONEW25-Mar-09 10:14 
GeneralRe: StreamWriter help... [modified] Pin
VoodooInfinity25-Mar-09 10:23
VoodooInfinity25-Mar-09 10:23 
AnswerRe: StreamWriter help... Pin
J$25-Mar-09 10:34
J$25-Mar-09 10:34 
AnswerRe: StreamWriter help... Pin
Ian Shlasko25-Mar-09 10:34
Ian Shlasko25-Mar-09 10:34 
QuestionC# and Data Acquisition Application Pin
stancrm25-Mar-09 10:06
stancrm25-Mar-09 10:06 
JokeRe: C# and Data Acquisition Application Pin
Eddy Vluggen25-Mar-09 10:31
professionalEddy Vluggen25-Mar-09 10:31 
AnswerRe: C# and Data Acquisition Application Pin
DaveyM6925-Mar-09 11:26
professionalDaveyM6925-Mar-09 11:26 
GeneralRe: C# and Data Acquisition Application Pin
Eddy Vluggen25-Mar-09 12:07
professionalEddy Vluggen25-Mar-09 12:07 
GeneralRe: C# and Data Acquisition Application Pin
DaveyM6925-Mar-09 12:17
professionalDaveyM6925-Mar-09 12:17 
AnswerRe: C# and Data Acquisition Application Pin
Luc Pattyn25-Mar-09 13:47
sitebuilderLuc Pattyn25-Mar-09 13:47 
QuestionKill a process in RDC session Pin
pranu_1325-Mar-09 9:48
pranu_1325-Mar-09 9:48 
AnswerRe: Kill a process in RDC session Pin
Ian Shlasko25-Mar-09 10:43
Ian Shlasko25-Mar-09 10:43 
GeneralRe: Kill a process in RDC session Pin
pranu_1325-Mar-09 12:21
pranu_1325-Mar-09 12:21 
GeneralRe: Kill a process in RDC session Pin
dano2k325-Mar-09 22:44
dano2k325-Mar-09 22:44 
QuestionAnalyzing the Traffic of network Pin
spiritboy25-Mar-09 9:41
spiritboy25-Mar-09 9:41 
AnswerRe: Analyzing the Traffic of network Pin
harold aptroot25-Mar-09 10:08
harold aptroot25-Mar-09 10:08 
QuestionHow long the database connection stays open Pin
netJP12L25-Mar-09 9:32
netJP12L25-Mar-09 9:32 

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.