我遇到了代码并运行它的麻烦。
我的代码:
//
// TODO: Add constructor code after the InitializeComponent() call.
//
textBox1.Text=("0.42");
textBox2.Text=("1.14");
textBox3.Text=("-0.71");
textBox4.Text=("-1.13");
textBox5.Text=("-2.15");
textBox6.Text=("0.81");
textBox7.Text=("7.05");
textBox8.Text=("5.11");
textBox9.Text=("-0.02");
textBox10.Text=("6.15");
textBox11.Text=("-4.16");
textBox12.Text=("-0.17");
}
void Button1Click(object sender, EventArgs e)
{
double z1,z2,z3,x1,x2,x3,c1,c2,c3,a1,a2,a3,n,s1,s2,s3;
z1=Convert.ToDouble(textBox1.Text);
z2=Convert.ToDouble(textBox2.Text);
z3=Convert.ToDouble(textBox3.Text);
x1=Convert.ToDouble(textBox4.Text);
x2=Convert.ToDouble(textBox5.Text);
x3=Convert.ToDouble(textBox6.Text);
c1=Convert.ToDouble(textBox7.Text);
c2=Convert.ToDouble(textBox8.Text);
c3=Convert.ToDouble(textBox9.Text);
a1=Convert.ToDouble(textBox10.Text);
a2=Convert.ToDouble(textBox11.Text);
a3=Convert.ToDouble(textBox12.Text);
n=x1/z1;
textBox24.Text=Convert.ToString(z1=n*z1);
textBox23.Text=Convert.ToString(z2=n*z2);
textBox22.Text=Convert.ToString(z3=n*z3);
textBox19.Text=Convert.ToString(x1=x1-z1);
textBox20.Text=Convert.ToString(x2=x2-z2);
textBox21.Text=Convert.ToString(x3=x3-z3);
textBox13.Text=Convert.ToString(a1=a1*n);
textBox14.Text=Convert.ToString(a2=a2-a1);
n=c1/z1;
textBox24.Text=Convert.ToString(z1=n*z1);
textBox23.Text=Convert.ToString(z2=n*z2);
textBox22.Text=Convert.ToString(z3=n*z3);
textBox16.Text=Convert.ToString(c1=c1-z1);
textBox17.Text=Convert.ToString(c2=c2-z2);
textBox18.Text=Convert.ToString(c3=c3-z3);
textBox13.Text=Convert.ToString(a1=a1*n);
textBox15.Text=Convert.ToString(a3=a3-a1);
n=c2/x2;
textBox32.Text=Convert.ToString(x2=x2*n);
textBox33.Text=Convert.ToString(x3=x3*n);
textBox29.Text=Convert.ToString(c2=c2-x2);
textBox30.Text=Convert.ToString(c3=c3-x3);
textBox26.Text=Convert.ToString(a2=a2*n);
textBox27.Text=Convert.ToString(a3=a3-a2);
textBox36.Text=textBox24.Text;
textBox35.Text=textBox23.Text;
textBox34.Text=textBox22.Text;
textBox25.Text=textBox13.Text;
n=(1/c3);
s1=Math.Round(n*a3,4);
label28.Text=("c="+s1);
s2=Math.Round((1/x2)*(a2-(x3*s1)),4);
label29.Text=("b="+s2);
s3=Math.Round((1/z1)*(a1-(z2*s2)-(z3*s1)),4);
label30.Text=("a="+s3);
}
}
这个程序是高斯方法练习。
当我运行程序时,我尝试按下按钮,然后弹出错误:
System.FormatException: Input string was not in a correct format. at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt) at System.Convert.ToDouble(String value) at gausa_metode_2_variants.MainForm.Button1Click(Object sender, EventArgs e) in c:\Users\NIKS\Documents\SharpDevelop Projects\gausa metode 2 variants\gausa metode 2 variants\MainForm.cs:line 48 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at gausa_metode_2_variants.Program.Main(String[] args) in c:\Users\NIKS\Documents\SharpDevelop Projects\gausa metode 2 variants\gausa metode 2 variants\Program.cs:line 27
答案 0 :(得分:0)
它无法解析字符串以使该行加倍
z1=Convert.ToDouble(textBox1.Text);
z2=Convert.ToDouble(textBox2.Text);
z3=Convert.ToDouble(textBox3.Text);
x1=Convert.ToDouble(textBox4.Text);
x2=Convert.ToDouble(textBox5.Text);
x3=Convert.ToDouble(textBox6.Text);
c1=Convert.ToDouble(textBox7.Text);
c2=Convert.ToDouble(textBox8.Text);
c3=Convert.ToDouble(textBox9.Text);
a1=Convert.ToDouble(textBox10.Text);
a2=Convert.ToDouble(textBox11.Text);
a3=Convert.ToDouble(textBox12.Text);
当我检查文本框值似乎没问题。没错,也许你正在改变运行时文本框的值。 最后,错误消息显示:
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDouble(String value) at line 48
所以只需检查您要在第48行解析的值
答案 1 :(得分:0)
在第48行将指定的string
转换为double
时遇到问题。
这将是**=Convert.ToDouble(textBox*.Text);
之一。
根据地区和区域设置,我非常确定您需要为小数分隔符编写,
(至少有些国家/地区使用,
代替.
)。