private void VolcanicsButton_Click(object sender, EventArgs e) { int.TryParse(numberTextBox.Text, out int temp); if (temp > 0) { int planetNumber = Int32.Parse(numberTextBox.Text); Excel excel = OpenFileAt(10); string planet = excel.ReadCellString(planetNumber, 2); //read row planet number column c excel.Close();//dellocate numberTextBox.Text = planet; RetrievePicture("Vol", planetNumber); } else if (VolcanicZoundsCheckBox.Checked && VolcanicsCheckBox.Checked) //both { Excel excel = OpenFileAt(10); int planet = (int)excel.ReadCellDouble(1, 8); //amount of planets output.WriteLine("Volcanics: "); for (int i = 1; i <= planet; i++) { WriteAllPlanetInfo(i, excel); } output.Flush(); excel.Close(); MessageBox.Show("Volcanics added to " + outputPath, "Completed"); } else if (VolcanicZoundsCheckBox.Checked && !VolcanicsCheckBox.Checked) //Volcanic Zounds only { Excel excel = OpenFileAt(10); int planet = (int)excel.ReadCellDouble(2, 8); //amount of zounds output.WriteLine("Volcanic Zounds: "); for (int i = 1; i <= planet; i++) { output.WriteLine(excel.ReadCellString(i, 5)); //column F } output.Flush(); excel.Close(); MessageBox.Show("Volcanics Zounds added to " + outputPath, "Completed"); } else if (!VolcanicZoundsCheckBox.Checked && VolcanicsCheckBox.Checked) //normies only { Excel excel = OpenFileAt(10); int planet = (int)excel.ReadCellDouble(1, 8); //amount of planets output.WriteLine("Volcanic Non-Zounds: "); for (int i = 1; i <= planet; i++) { string box = excel.ReadCellString(i, 2); for (int j = 0; j < box.Length; j++)//go through string { if (box[j].Equals('.')) { if (j + 5 < box.Length && !box[j + 5].Equals('Z')) { output.WriteLine(excel.ReadCellString(i, 2)); //column C } else if (j + 3 == box.Length - 1 && !box[j - 4].Equals('.')) { output.WriteLine(excel.ReadCellString(i, 2)); //column C } } } } output.Flush(); excel.Close(); MessageBox.Show("Volcanics without Zounds added to " + outputPath, "Completed"); } else { MessageBox.Show("Nothing was selected"); } }
private Excel OpenFileAt(int num) { Excel excel = new Excel(excelPath, num); return excel; }