现在写了一个小公式,出现错误了 往下不会做了。
程序界面如下
代码 入下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace 对流程延迟值
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
double P, T, Td, H, angle;
double hop_dry,hop_wet,Saas_dry,Saas_wet;
P = Convert.ToDouble(txtP.Text);
T = Convert.ToDouble(txtT.Text);
Td = Convert.ToDouble(txtTd.Text);
H = Convert.ToDouble(txtH.Text);
angle = Convert.ToDouble(txtangle.Text);
if (rbDry.Checked && rbHuopu.Checked)
{
txtResult.Text = hop_dry.ToString();
}
else if (rbDry.Checked && rbSasi.Checked)
{
txtResult.Text = Saas_dry.ToString();
}
else if (rbWet.Checked && rbHuopu.Checked)
{
txtResult.Text = hop_wet.ToString();
}
else if (rbWet.Checked && rbSasi.Checked)
{
txtResult.Text = Saas_wet.ToString();
}
else
{
MessageBox.Show("您选择的不对,请重新选择", "信息提示", MessageBoxButtons.OK);
}
}
//模型计算方式
public double Hopfield_dry(double P, double T, double H ) //霍普菲尔德模型干延迟
{
T = T + 273.16;
double hop_dry = 155.2 * Math.Pow(10, -7) * (P / T) * (40136 + 148.72 * (T - 273.16) - H);
return hop_dry;
}
public double Hopfield_wet(double T, double Td, double H) //霍普菲尔德模型湿延迟
{
T = T + 273.16;
double hop_wet = 155.2 * Math.Pow(10, -7) * (4810 / (T * T)) * (6.11 * Math.Pow(10, (7.5 / (1 + 237.3 / Td)))) * (11000 - H);
return hop_wet;
}
public double Saastamoinen_dry(double P, double H, double Angle) //萨斯塔莫宁模型干延迟
{
double Saas_dry = 2.2768 * P / (1 - 0.00266 * Math.Cos(Angle / 206265) - 0.0028 * H);
return Saas_dry;
}
public double Saastamoinen_wet(double T, double Td, double H, double Angle) //萨斯塔莫宁湿延迟
{
T = T + 273.16;
double Saas_wet = (0.002277 / (1 - 0.00266 * Math.Cos(Angle / 206265) - 0.0028 * H)) * (1255 / T + 0.05) * (6.11 * Math.Pow(10, (7.5 / (1 + 237.3 / Td))));
return Saas_wet;
}
}
}
------解决思路----------------------
你下面这一坨代码中使用的这些变量都没有赋初始值hop_dry,hop_wet,Saas_dry,Saas_wet,还是Null你就调用ToString()方法
if (rbDry.Checked && rbHuopu.Checked)
{
txtResult.Text = hop_dry.ToString();
}
else if (rbDry.Checked && rbSasi.Checked)
{
txtResult.Text = Saas_dry.ToString();
}
else if (rbWet.Checked && rbHuopu.Checked)
{
txtResult.Text = hop_wet.ToString();
}
else if (rbWet.Checked && rbSasi.Checked)
{
txtResult.Text = Saas_wet.ToString();
}
else
{
MessageBox.Show("您选择的不对,请重新选择", "信息提示", MessageBoxButtons.OK);
}
解决办法:
给这些变量赋值,后再使用
double hop_dry, hop_wet, Saas_dry, Saas_wet = 0;
------解决思路----------------------