11

このエラーは単純なはずですが、うまくいかないようです。問題は、このまったく同じコードがプログラムの早い段階で機能するという事実にあります。前の 4 つのインスタンスではなく、このインスタンスでエラーを送信する理由はわかりません。以下のコードを参照し、私がより良くなるはずなので、あなたが持っているかもしれない批判を自由に提供してください. 問題があれば、私は Sharp Develop 2.2 を使用しています。

動作するコードの例を次に示します。

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();

    }

この投稿の件名でエラーを送信するコードの例を次に示します。

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();
        }

    }

私が得ることができる助けに感謝します。ありがとうございました。

4

3 に答える 3

28
.8m instead of .8
于 2008-12-12T18:31:28.310 に答える
4

あなたはそれがどのセリフかは言いませんでしたが、私は次の 2 つに賭けています。

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

と:

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

.8 には「m」修飾子がないことに注意してください。私が見た他のすべての場所では、あなたがそれを提供していました。

于 2008-12-12T18:32:55.470 に答える
3

ここのこの行で:

z = ( xy) (.8 * 1.732050808m);

.8 をリテラルとして指定しますが、'm' 接尾辞がない場合、リテラルは double を指定します。

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

それを修正します。

于 2008-12-12T18:32:11.587 に答える