我收到錯誤「格式異常未處理」。和「輸入字符串格式不正確」。它在這一行temp_i = float.Parse(textBox3.Text);問題是什麼?格式異常未處理。輸入字符串格式不正確
//button 2 calculate button
private void button1_Click(object sender, EventArgs e)
{
float temp_e;
float temp_i;
float temp_r;
float temp_p;
//*******************************************************
// Resistance = Volts/Current
//*******************************************************
if (IsNumeric(textBox1.Text) &&
IsNumeric(textBox2.Text) &&
textBox3.Text == (""))
{
temp_e = float.Parse(textBox1.Text); //convert string to number
temp_i = float.Parse(textBox3.Text); //convert string to number
temp_r = temp_e/temp_i; //display 1st result
textBox2.Text = Convert.ToString(temp_r); //post result resistance (R)
//calculate power
temp_p = temp_e * temp_i;
textBox5.Text = Convert.ToString(temp_p);
//display 2nd result
textBox4.Text = Convert.ToString(temp_r) + " * " + Convert.ToString(temp_i) + " = " + Convert.ToString(temp_p) + " watts";
}'
你會怎樣想轉換「」浮動?你確定 ?嘗試刪除該條件,否則解析並比較它。 – Milee 2012-04-23 11:02:17