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

VulpesPosted May 13, 2014, 10:07 AM
File.AppendAllLines(@"C:\Delta Sigma\Log.txt", new string[1]{textBox1.Text});
Farhan ShariffPosted May 13, 2014, 11:40 AM
VulpesPosted May 13, 2014, 11:36 AM
Farhan ShariffPosted May 13, 2014, 11:06 AM
Farhan ShariffPosted May 13, 2014, 10:57 AM
private void textBox1_Leave(object sender, EventArgs e)
{
File.AppendAllLines(@"C:\Delta Sigma\Log.txt", new string[1] {"Critical Delta Sigma:" +textBox1.Text });
}
VulpesPosted May 13, 2014, 10:48 AM
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 ShariffPosted May 13, 2014, 10:43 AM
private void textBox1_Leave(object sender, EventArgs e)
{
File.AppendAllText(@"C:\Delta Sigma\Log.txt", "\r\n" + textBox1.Text);
}
VulpesPosted May 13, 2014, 10:39 AM
Farhan ShariffPosted May 13, 2014, 10:35 AM
VulpesPosted May 13, 2014, 10:29 AM
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 ShariffPosted May 13, 2014, 10:25 AM
Let me check
Farhan ShariffPosted May 13, 2014, 10:16 AM
Farhan ShariffPosted May 13, 2014, 10:10 AM
No it is not working it is printing as
1
1.
1.5
VulpesPosted May 13, 2014, 9:54 AM
Try instead:
File.AppendAllText(@"C:\Delta Sigma\Log.txt", "\r\n" + textBox1.Text);