2008-12-12 15 views
10

के संचालन पर लागू नहीं किया जा सकता है यह त्रुटि एक साधारण होनी चाहिए लेकिन मैं इसे काम नहीं कर सकता। समस्या इस तथ्य में निहित है कि यह वही कोड प्रोग्राम में पहले काम करता है। मुझे इस उदाहरण पर कोई त्रुटि भेजने के लिए कोई कारण नहीं दिख रहा है, न कि चार पिछले। नीचे दिए गए कोड का संदर्भ लें, और आपको कोई भी आलोचना प्रदान करने में संकोच न करें क्योंकि इससे मुझे बेहतर बनाना चाहिए। यदि यह मायने रखता है, तो मैं तीव्र विकास 2.2 का उपयोग कर रहा हूं।सी #, ऑपरेटर '*' को 'डबल' और 'दशमलव'

void Calc4Click(object sender, EventArgs e) 
{ 
     if (!String.IsNullOrEmpty(tb4_fla.Text) && String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_kw.Text) & String.IsNullOrEmpty(tb4_e.Text) || String.IsNullOrEmpty(tb4_e.Text)) 
     { //If values are entered improperly, the following message box will appear 
     MessageBox.Show("Enter either FLA and Voltage or kW and Voltage", "Invalid Data Entry", MessageBoxButtons.OK); 
     } 


     if (!String.IsNullOrEmpty(tb4_fla.Text)&& !String.IsNullOrEmpty(tb4_e.Text)&& String.IsNullOrEmpty(tb4_kw.Text)) 
     {//If the user eneters FLA and Voltage calculate for kW 

      decimal x, y, z; 
      x = decimal.Parse(tb4_fla.Text); 
      y = decimal.Parse(tb4_e.Text); 
      z = (x*y)*(.8 * 1.732050808m); 
      tb4_kw.Text = Math.Round(z,0).ToString(); 

     }    

     if (!String.IsNullOrEmpty(tb4_kw.Text) && !String.IsNullOrEmpty(tb4_e.Text) && String.IsNullOrEmpty(tb4_fla.Text)) 
     {;//If the user enters kW and Voltage calculate for FLA 
      decimal x, y, z; 
      x = decimal.Parse(tb4_kw.Text); 
      y = decimal.Parse(tb4_e.Text); 
      z = (1000 * x)/(y * 1.732050808m)* .8; 
      tb4_fla.Text = Math.Round(z,0).ToString(); 
     } 

    } 

मैं किसी भी सराहना करते हैं:

void calc2Click(object sender, EventArgs e) 
{ 
    if (!String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_fla.Text) & String.IsNullOrEmpty(tb2_e.Text) | String.IsNullOrEmpty(tb2_e.Text)) 
    { 
     MessageBox.Show("Enter either kVA and Voltage or FLA and Voltage", "Invalid Data Entry", MessageBoxButtons.OK); 
    }  

     if (!String.IsNullOrEmpty(tb2_kva.Text) & !String.IsNullOrEmpty(tb2_e.Text)) 
    { 
      decimal x, y, z; 
      x = decimal.Parse(tb2_kva.Text);  
      y = decimal.Parse(tb2_e.Text); 
      z = (x * 1000)/(1.732050808m * y); //the m at the end of the decimal allows for the multiplication of decimals  
      tb2_fla.Text = z.ToString(); 
      tb2_fla.Text = Math.Round(z,2).ToString(); 
    } 
     else 
    { 
     if (!String.IsNullOrEmpty(tb2_fla.Text) & !String.IsNullOrEmpty(tb2_e.Text)) 
    { 
      decimal x, y, z; 
      x = decimal.Parse(tb2_fla.Text);  
      y = decimal.Parse(tb2_e.Text); 
      z = (x * y * 1.732050808m)/1000; //the m at the end of the decimal allows for the multiplication of decimals 
      tb2_kva.Text = Math.Round(z,2).ToString(); 

    } 

यहाँ कोड है कि इस पोस्ट के विषय पंक्ति में त्रुटि भेजता का उदाहरण है:

यहाँ कोड का एक उदाहरण है कि काम करता है मदद मैं प्राप्त कर सकते हैं। धन्यवाद।

उत्तर

27
.8m instead of .8 
+0

इसे इंगित करने के लिए धन्यवाद। मैं चुपचाप उम्मीद कर रहा था कि यह इतना आसान नहीं था। :) –

+0

एम के लिए क्या खड़ा है? – Alex

+1

मीटर शाब्दिक को दशमलव के रूप में व्याख्या करने के लिए मजबूर करता है। – Broam

3

इस लाइन यहाँ में:

z = (एक्स वाई) (.8 * 1.732050808m);

आप एक शाब्दिक के रूप में .8 निर्दिष्ट करते हैं, लेकिन 'एम' प्रत्यय के बिना, शाब्दिक एक डबल निर्दिष्ट करता है।

z = (x y) (.8m * 1.732050808m);

इसे ठीक करेगा।

4

आप यह नहीं कहा जो लाइन यह था, लेकिन मैं इन दोनों पर दांव लगा रही है:

z = (x*y)*(.8 * 1.732050808m); 

और:

z = (1000 * x)/(y * 1.732050808m)* .8; 

ध्यान रखें कि आपके .8 'मी नहीं है 'क्वालीफायर। मैं देखता हूं कि हर दूसरी जगह आपने आपूर्ति की है।

संबंधित मुद्दे