2015-11-17 29 views
0
 double HP, L, hr, Est, eee, result; 
     string output; 
     HP = double.Parse(textBox1.Text); 
     L = double.Parse(textBox2.Text); 
     hr = double.Parse(textBox3.Text); 
     Est = double.Parse(textBox4.Text); 
     eee = double.Parse(textBox5.Text); 

     result = HP * (L/100) * 0.746 * hr * (((1/Est) - (1/eee)) * 100); 
     output = " " + result; 

     textBox6.Text = output;   

我想在一個或多個文本框爲空時顯示驗證消息。當texboxes爲空時顯示驗證錯誤

+0

「不完整」是什麼意思?當一個字段(textBoxX)爲空時? –

+0

是文本框爲空 –

+0

基於OP的評論,問題是關於將輸入驗證添加到文本框,所以我已經重寫了這個問題以說明問題。 – markpsmith

回答

0

驗證字段不爲空:

if(!String.IsNullOrEmpty(textBox.Text) && String.IsNullOrEmpty(...)){ 

} 

檢查是值是有效的double:

double parsedValue; 

if (!double.TryParse(textBox.Text, out parsedValue)) 
{ 
    MessageBox.Show("This is a double only field"); 
    return; 
} 

你會得到這樣的事情:

if(nullorempty tests){ 
    if(youcanparse first textbox){ 
     the value of that textbox is not valid 
    } else if(youcanparse second textbox){ 
     ... 
    } 
} else { 
    show "you must enter something !" 
} 

+0

不錯@Alexender –

+0

@ Uit14bs這應該會有訣竅,如果還有其他問題,請回來! :) –

+0

@Alexender Beaudet這是理解問題的遊戲 –