Validation Parse System
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace assignment_5_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button_exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void button_calculate_Click(object sender, EventArgs e)
{
bool mph_ok = false;
bool hour_ok = false;
string tb_input_mph = textBox_mph.Text;
string tb_input_hours = textBox_hours.Text;
int tb_input_mph_int;
int tb_input_hours_int;
if (int.TryParse(tb_input_mph, out tb_input_mph_int))
{
mph_ok = true;
}
if (int.TryParse(tb_input_hours, out tb_input_hours_int))
{
hour_ok = true;
}
if (mph_ok && hour_ok)
{
listBox_output.Items.Clear();
for (int count = 1; count <= tb_input_hours_int; count++)
{
listBox_output.Items.Add("After hour " + count + " the distance is " + (count * tb_input_mph_int));
}
}
else
{
MessageBox.Show("Please enter a number for MPH and hours.");
textBox_mph.Focus();
}
}
}
}