我的代码出错,我需要帮助请求 [英] I Have An Error On My Code, I Need Help Pleas

查看:82
本文介绍了我的代码出错,我需要帮助请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误

((  Error   6   The name 'Conversion' does not exist in the current context C:\Visual Studio 2010\Projects\Graduation System\Graduation System\ Grade1.cs   120 30  Graduation System))



<pre lang="cs">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Microsoft.VisualBasic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Graduation
{
    public partial class Grade1 : Form
    {
        public Grade1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            int a = default(int);
            decimal b = new decimal();

            if (Information.IsNumeric(TextBox3.Text))
            {
                if (int.Parse(TextBox3.Text) &lt;= 20)
                {
                    a = (int)((double.Parse(TextBox3.Text) * 100) / 20);
                    TextBox4.Text = a.ToString();
                    b = (decimal)(a * 0.1);
                    TextBox5.Text = b.ToString();
                }
                else
                {
                    MessageBox.Show(&quot;Please Enter value equal to 20 and below!&quot;);
                }
            }
            if (Information.IsNumeric(TextBox6.Text))
            {

                if (int.Parse(TextBox6.Text) &lt;= 50)
                {
                    int c = default(int);
                    decimal d = new decimal();
                    c = (int)((double.Parse(TextBox6.Text) * 100) / 50);
                    TextBox7.Text = c.ToString();
                    d = (decimal)(c * 0.1);
                    TextBox8.Text = d.ToString();

                }
                else
                {
                    MessageBox.Show(&quot;Please Enter value equal to 50 and below!&quot;);


                }
            }

            if (Information.IsNumeric(TextBox9.Text))
            {
                if (int.Parse(TextBox9.Text) &lt;= 50)
                {
                    int g = default(int);
                    decimal f = new decimal();
                    g = (int)((double.Parse(TextBox9.Text) * 100) / 50);
                    TextBox10.Text = g.ToString();
                    f = (decimal)(g * 0.2);
                    TextBox11.Text = f.ToString();

                }
                else
                {
                    MessageBox.Show(&quot;Please Enter value equal to 50 and below!&quot;);


                }
            }
            if (Information.IsNumeric(TextBox12.Text))
            {
                if (int.Parse(TextBox12.Text) &lt;= 100)
                {
                    int g = default(int);
                    decimal f = new decimal();
                    g = (int)((double.Parse(TextBox12.Text) * 100) / 100);
                    TextBox13.Text = g.ToString();
                    f = (decimal)(g * 0.3);
                    TextBox14.Text = f.ToString();

                }
                else
                {
                    MessageBox.Show(&quot;Please Enter value equal to 100 and below!&quot;);


                }
            }

            if (Information.IsNumeric(TextBox15.Text))
            {
                if (int.Parse(TextBox15.Text) &lt;= 100)
                {
                    int j = default(int);
                    decimal f1 = new decimal();
                    j = (int)((double.Parse(TextBox15.Text) * 100) / 100);
                    TextBox16.Text = j.ToString();
                    f1 = (decimal)(j * 0.3);
                    TextBox17.Text = f1.ToString();

                }
                else
                {
                    MessageBox.Show(&quot;Please Enter value equal to 100 and below!&quot;);


                }
            }

            decimal adal = new decimal();
            adal = (decimal)(Conversion.Val(TextBox5.Text) + Conversion.Val(TextBox8.Text) + Conversion.Val(TextBox11.Text) + Conversion.Val(TextBox14.Text) + Conversion.Val(TextBox17.Text));

            TextBox18.Text = adal.ToString();

            if (Conversion.Val(TextBox18.Text) &lt;= 74)
            {

                TextBox19.Text = &quot;Failed&quot;;
                TextBox19.ForeColor = Color.Red;
            }
            else if (Conversion.Val(TextBox18.Text) &lt;= 84)
            {
                TextBox19.Text = &quot;Good&quot;;
                TextBox19.ForeColor = Color.Black;
            }
            else if (Conversion.Val(TextBox18.Text) &lt;= 94)
            {
                TextBox19.Text = &quot;Very Good&quot;;
                TextBox19.ForeColor = Color.Black;
            }
            else
            {
                TextBox19.Text = &quot;Excellent&quot;;
                TextBox19.ForeColor = Color.Black;


            }

        }

        private void Button3_Click(object sender, EventArgs e)
        {

            TextBox1.Text = &quot;&quot;;
            TextBox12.Text = &quot;&quot;;
            TextBox3.Text = &quot;&quot;;
            TextBox4.Text = &quot;&quot;;
            TextBox5.Text = &quot;&quot;;
            TextBox6.Text = &quot;&quot;;
            TextBox7.Text = &quot;&quot;;
            TextBox8.Text = &quot;&quot;;
            TextBox9.Text = &quot;&quot;;
            TextBox10.Text = &quot;&quot;;
            TextBox11.Text = &quot;&quot;;
            TextBox12.Text = &quot;&quot;;
            TextBox13.Text = &quot;&quot;;
            TextBox14.Text = &quot;&quot;;
            TextBox15.Text = &quot;&quot;;
            TextBox16.Text = &quot;&quot;;
            TextBox17.Text = &quot;&quot;;
            TextBox18.Text = &quot;&quot;;
            TextBox19.Text = &quot;&quot;;


        }
    }
}</pre>

推荐答案

不是错误明确?你正在使用未定义的东西:

Conversion.Val(TextBox5.Text)+ Conversion.Val(TextBox8.Text)



转换是VB特定的,你应该包括Microsoft.VisualBasic命名空间(坏)或(更好)使用相应类型的TryParse或Parse方法。 decimal.TryParse例如。



如果这有帮助请花时间接受解决方案。谢谢。
Isn't the error clear? You're using something that is not defined:
Conversion.Val(TextBox5.Text) + Conversion.Val(TextBox8.Text)

Conversion is VB specific, you should either include Microsoft.VisualBasic namespace (bad) or (better) use TryParse or Parse methods of corresponding types. decimal.TryParse for example.

If this helps please take time to accept the solution. Thank you.


除非它是某个地方的某个自定义类,否则这个转换类不存在:

Unless it's some custom class from somewhere, this "Conversion"-class doesn't exist:
decimal adal = new decimal();
adal = (decimal)(Conversion.Val(TextBox5.Text) + Conversion.Val(TextBox8.Text) + Conversion.Val(TextBox11.Text) + Conversion.Val(TextBox14.Text) + Conversion.Val(TextBox17.Text));

我猜你打算改用转换类。

此外new decimal(); - 语句虽然语法上很好,但完全没用。整个代码应该是这样的:

I guess you intended to use the "Convert"-class instead.
Furthermore that "new decimal();"-Statement is, albeit syntactically alright, completely useless. That whole code should look like this instead:

decimal adal = Convert.ToDecimal(TextBox5.Text) + Convert.ToDecimal(TextBox8.Text) + Convert.ToDecimal(TextBox11.Text) + Convert.ToDecimal(TextBox14.Text) + Convert.ToDecimal(TextBox17.Text);



请注意,如果任何TextBox不包含可转换为小数的格式的字符串,您将获得FormatException。


Be aware though that you'll get a FormatException if any of those TextBoxes don't contain a string that has a format convertible to a decimal.


这篇关于我的代码出错,我需要帮助请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆