I am trying to copy the double value from text box to file but values are written multiple times, Meaning if I write 1.5 in text box I get 1 ,1. , 1.5 in text file
private void textBox1_TextChanged(object sender, EventArgs e)
{
StreamWriter sw = new StreamWriter(@"C:\Delta Sigma\Log.txt",true);
sw.WriteLine("Critical Delta Sigma:", textBox1.Text);
sw.Close();
}
Loading


VulpesRank #55 · 29.2K reputationPosted May 13, 2014, 6:07 AM EDT
File.AppendAllLines(@"C:\Delta Sigma\Log.txt", new string[1]{textBox1.Text});
VulpesRank #55 · 29.2K reputationPosted May 13, 2014, 5:54 AM EDT
Try instead:
File.AppendAllText(@"C:\Delta Sigma\Log.txt", "\r\n" + textBox1.Text);
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 6:10 AM EDT
No it is not working it is printing as
1
1.
1.5
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 6:16 AM EDT
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 6:25 AM EDT
Let me check
VulpesRank #55 · 29.2K reputationPosted May 13, 2014, 6:29 AM EDT
Have you by any chance got this code in the TextBox's TextChanged event-handler?
If you have then it would explain the output you're seeing in the file.
If you want to print it automatically when focus leaves the TextBox, I'd put it in the Leave event-handler instead.
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 6:35 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 13, 2014, 6:39 AM EDT
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 6:43 AM EDT
private void textBox1_Leave(object sender, EventArgs e)
{
File.AppendAllText(@"C:\Delta Sigma\Log.txt", "\r\n" + textBox1.Text);
}
VulpesRank #55 · 29.2K reputationPosted May 13, 2014, 6:48 AM EDT
Now place this line (or whatever you're currently using) in the handler:
File.AppendAllLines(@"C:\Delta Sigma\Log.txt", new string[1]{textBox1.Text});
You'll also need to remove the TextChanged handler which you can either do by deleting it in the Properties Box or leaving it in the code but removing the contents.
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 6:57 AM EDT
private void textBox1_Leave(object sender, EventArgs e)
{
File.AppendAllLines(@"C:\Delta Sigma\Log.txt", new string[1] {"Critical Delta Sigma:" +textBox1.Text });
}
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 7:06 AM EDT
VulpesRank #55 · 29.2K reputationPosted May 13, 2014, 7:36 AM EDT
Farhan ShariffRank #2,004 · 725 reputationPosted May 13, 2014, 7:40 AM EDT