New to programming, need help

Hi. I'm new to programming and I'm working on a stopwatch in WinForm. I need it to be able to create log files of the times, but when I click it, it creates a blank .txt of clock 1, a .txt of clock 2 with the time from clock 1, and doesn't even create a file for clock 3. I cannot spot where I went wrong (Forgive my painfully bad skills):

EDIT: I don't know why it doesn't display the first couple lines correctly. It looks like the rest of the code in my project.

EDIT 2: Forgot half of my code. Here it is. Sorry, very green.

public Form1() { InitializeComponent(); System.IO.Directory.CreateDirectory(@".\ComputerLogs"); } int hour1, min1, sec1 = 0; int hour2, min2, sec2 = 0; int hour3, min3, sec3 = 0;

 string log1 = ""; string log2 = ""; string log3 = ""; private void button61_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("explorer.exe", @".\ComputerLogs"); } private void savefile(string computer) { System.IO.StreamWriter file = new System.IO.StreamWriter(@".\ComputerLogs\" + computer + ".txt"); file.WriteLine(log1); file.Close(); } private void timer1_Tick(object sender, EventArgs e) // Timer 1 { label21.Text = hour1 + ":" + min1 + ":" + sec1.ToString(); sec1++; if (sec1 > 59) { min1++; sec1 = 0; } if (min1 > 59) { hour1++; min1 = 0; } } private void button1_Click(object sender, EventArgs e) // Start 1 { timer1.Start(); } private void label21_Click(object sender, EventArgs e) // Tid 1 { } private void button21_Click(object sender, EventArgs e) // Stop 1 { timer1.Stop(); savefile("Computer 1"); log1 = "Computer 1: " + label21.Text; } private void button41_Click(object sender, EventArgs e) // Reset 1 { sec1 = 0; min1 = 0; hour1 = 0; label21.Text = "0:0:0"; } private void timer2_Tick(object sender, EventArgs e) // Timer 2 { label22.Text = hour2 + ":" + min2 + ":" + sec2.ToString(); sec2++; if (sec2 > 59) { min2++; sec2 = 0; } if (min2 > 59) { hour2++; min2 = 0; } } private void button2_Click(object sender, EventArgs e) // Start 2 { timer2.Start(); } private void label22_Click(object sender, EventArgs e) // Tid 2 { } private void button22_Click(object sender, EventArgs e) // Stop 2 { timer2.Stop(); savefile("Computer 2"); log2 = "Computer 2: " + label22.Text; } private void button42_Click(object sender, EventArgs e) // Reset 2 { sec2 = 0; min2 = 0; hour2 = 0; label22.Text = "0:0:0"; } private void timer3_Tick(object sender, EventArgs e) // Timer 3 { label23.Text = hour3 + ":" + min3 + ":" + sec3.ToString(); sec3++; if (sec3 > 59) { min3++; sec3 = 0; } if (min3 > 59) { hour3++; min3 = 0; } } private void button3_Click(object sender, EventArgs e) // Start 3 { timer3.Start(); } private void label23_Click(object sender, EventArgs e) // Tid 3 { } private void button23_Click(object sender, EventArgs e) // Stop 3 { timer3.Stop(); savefile("Computer 3"); log3 = "Computer 3: " + label23.Text; } private void button43_Click(object sender, EventArgs e) // Reset 3 { sec3 = 0; min3 = 0; hour3 = 0; label23.Text = "0:0:0"; } } 

}

by imanononreddit via /r/csharp

Leave a Reply