全局变量数组、datatable赋值

using LEADCalculator;
using LEADjisuanqi;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LEADjisuanqi
{
    public partial class Calculator2 : Form
    {
        double Cosβ = 0.9425;
        double pai = 3.14;
        double g = 9.8;
        double l = 1000;
        double λ = 21.9;
        double ρ = 7.85 * 1000;
        string[] inputBefore0 = new string[15];
        string[] inputBefore1 = new string[9];
        string[] inPutNow0 = new string[15]; 
        string[] inPutNow1 = new string[9];
        string resultBefore0;
        string resultBefore1;
        string resultNow0;
        string resultNow1;
        int pageindex;
        int times0 = 0;
        int times1 = 0;

        public Calculator2()
        {
            InitializeComponent();

            textBox1.Visible = true;
            textBox3.Visible = false;
        }

        //根据当前界面选择相应公式计算结果    
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.xtraTabControl1.SelectedTabPageIndex == 0)
            {
                if (times1 != 0)
                {
                    if (times1 != 1)
                    {
                        inputBefore0 = inPutNow0;
                        resultBefore0 = resultNow0;
                    }
                    CalculationProcess0();
                }
            }
            else if (this.xtraTabControl1.SelectedTabPageIndex == 1)
            {
                inputBefore1 = inPutNow1;
                resultBefore1 = resultNow1;

                CalculationProcess1();
            }
        }
        private void CalculationProcess0()
        {
            CalculationStart0();

            inPutNow0[0] = txtSm1.Text;
            inPutNow0[1] = txtSm2.Text;
            inPutNow0[2] = txtSDirection.Text;
            inPutNow0[3] = txtSa.Text;
            inPutNow0[4] = txtSh.Text;
            inPutNow0[5] = txtSd.Text;
            inPutNow0[6] = txtSL.Text;
            inPutNow0[7] = txtSJExample.Text;
            inPutNow0[8] = txtSV.Text;
            inPutNow0[9] = txtSi.Text;
            inPutNow0[10] = txtSK.Text;
            inPutNow0[11] = txtSJc.Text;
            inPutNow0[12] = txtSMExample.Text;
            inPutNow0[13] = txtSla.Text;
            inPutNow0[14] = txtSμ.Text;

            if (times0 == 0)
            {
                resultBefore0 = resultNow0;
                inputBefore0 = inPutNow0;
            }
            else 
            {
                textBox2.Text = resultBefore0;
            }
            textBox1.Text = resultNow0;
            times0++;
        }

        private void CalculationProcess1()
        {
            CalculationStart1();
            
            string[] inPutTemper1 = new string[9];
            inPutTemper1[0] = txtCV.Text;
            inPutTemper1[1] = txtCi.Text;
            inPutTemper1[2] = txtCk.Text;
            inPutTemper1[3] = txtCa.Text;
            inPutTemper1[4] = txtCm.Text;
            inPutTemper1[5] = txtCz.Text;
            inPutTemper1[6] = txtCW.Text;
            inPutTemper1[7] = txtCn.Text;
            inPutTemper1[8] = txtCμ.Text;

            inPutNow1 = inPutTemper1;

            textBox3.Text = resultNow1;
            textBox4.Text = resultBefore1;
            
            times1++;
        }

        //计算过程
        private void CalculationStart0()
        {
            double m1 = Convert.ToDouble(txtSm1.Text);
            double m2 = Convert.ToDouble(txtSm2.Text);
            double Direction = Convert.ToDouble(txtSDirection.Text);
            double a = Convert.ToDouble(txtSa.Text);
            double h = Convert.ToDouble(txtSh.Text);
            double d = Convert.ToDouble(txtSd.Text);
            double L = Convert.ToDouble(txtSL.Text);
            double JExample = Convert.ToDouble(txtSJExample.Text);
            double V = Convert.ToDouble(txtSV.Text);
            double i = Convert.ToDouble(txtSi.Text);
            double K = Convert.ToDouble(txtSK.Text);
            double Jc = Convert.ToDouble(txtSJc.Text);
            double MExample = Convert.ToDouble(txtSMExample.Text);
            double la = Convert.ToDouble(txtSla.Text);
            double μ = Convert.ToDouble(txtSμ.Text);

            double m;
            double F;
            double Mf;
            double Fa;
            double Ma;
            double M;
            double Jload;
            double P2;
            double N1;
            double Jt;
            double MElec;
            double JElec;
            double nElec;
            double N1V;
            double P1;
            double Js;

            m = m1 + m2;
            F = m * g * μ;
            Mf = F * h / 2 * pai;
            Fa = F + m * a;
            Ma = Fa * h / 2 * pai;
            M = m * a;
            Jload = m * (h / 2 * pai) * (h / 2 * pai);
            P2 = 116 * (d * l) * (d * l);           //????????????
            N1 = λ * d * l / la * la * Math.Pow(10, 7);        //??????????
            MElec = Ma / i;
            JElec = Jload / (i * i) / K;   //??????
            nElec = V * i / h;
            N1V = N1 * h / i;
            N1 = λ * (d * 1000) / ((la * 1000) * (la * 1000)) * Math.Pow(10,7);
            P1 = 0;                                 //?????????????
            Js = Math.Pow(d,4)* L * pai * ρ / 32;   //????
            Jt = Jload + Js + Jc;

            resultNow0 = "\r\n" + "\r\n" + "\r\n"
            + "摩擦力(F): " + (Math.Round(F * 10000) / 10000).ToString() + " N" + "\r\n"
            + "丝杠惯量(Js): " + (Math.Round(Js * 10000) / 10000).ToString() + " Kg.m^2" + "\r\n"
            + "摩擦扭矩(Mf): " + (Math.Round(Mf * 10000) / 10000).ToString() + " Nm" + "\r\n"
            + "最大总扭矩(M): " + (Math.Round(M * 10000) / 10000).ToString() + " Nm" + "\r\n"
            + "N1下的直线速度: " + (Math.Round(N1V * 10000) / 10000).ToString() + "\r\n"
            + "负载总惯量(Jt): " + (Math.Round(Jt * 10000) / 10000).ToString() + " Kg.m^2" + "\r\n"
            + "加速所需的力(Fa): " + (Math.Round(Fa * 10000) / 10000).ToString() + " N" + "\r\n"
            + "加速所需扭矩(Ma): " + (Math.Round(Ma * 10000) / 10000).ToString() + " Nm" + "\r\n"
            + "丝杠挫曲载荷(P1): " + (Math.Round(P1 * 10000) / 10000).ToString() + " N" + "\r\n"
            + "电机应有扭矩(M电): " + (Math.Round(MElec * 10000) / 10000).ToString() + "\r\n"
            + "电机应有惯量(J电): " + (Math.Round(JElec * 10000) / 10000).ToString() + "\r\n"
            + "电机应有转速(n电): " + (Math.Round(nElec * 10000) / 10000).ToString() + " r/min" + "\r\n"
            + "丝杠的危险转速(N1): " + (Math.Round(N1 * 10000) / 10000).ToString() + " r/min" + "\r\n"
            + "工件+移动件重量(m): " + (Math.Round(m * 10000) / 10000).ToString() + " Kg" + "\r\n"
            + "台面产生的惯量(Jload): " + (Math.Round(Jload * 10000) / 10000).ToString() + " Kg.m^2" + "\r\n"
            + "丝杠容许压缩拉伸负荷(P2): " + (Math.Round(P2 * 10000) / 10000).ToString() + " N" + "\r\n";

        }

        //计算过程
        private void CalculationStart1()
        {
            double W = Convert.ToDouble(txtCW.Text);
            double μ = Convert.ToDouble(txtCμ.Text);
            double a = Convert.ToDouble(txtCa.Text);
            double m = Convert.ToDouble(txtCm.Text);
            double n = Convert.ToDouble(txtCn.Text);
            double z = Convert.ToDouble(txtCz.Text);
            double V = Convert.ToDouble(txtCV.Text);
            double i = Convert.ToDouble(txtCi.Text);
            double k = Convert.ToDouble(txtCk.Text);
            double Jload;
            double F;
            double M;
            double Fa;
            double Ma;
            double MElec;
            double JElec;
            double nElec;
            double L;
            double ZhiXian;

            Jload = W * (m * z / Cosβ / 2) * (m * z / Cosβ / 2) * 0.01;
            F = W * 9.8 * μ;
            M = F * (m * z / 0.9425 / 2) * 0.001;
            Fa = F + W * a;
            L = pai * m * z / Cosβ;
            Ma = Fa * (m * z / Cosβ / 2) * 0.001;
            MElec = Ma / i;
            JElec = (Jload / (i * i)) / k;
            nElec = V * i * Cosβ / pai / m / z * 1000;
            ZhiXian = L / 360 * n / 60;

            resultNow1 = "\r\n" + "\r\n" + "\r\n"
             + "负载产生的惯量(Jload): " + (Math.Round(Jload * 10000) / 10000).ToString() + " Kg.cm^2" + "\r\n"
             + "负载产生的力(F): " + (Math.Round(F * 10000) / 10000).ToString() + " N" + "\r\n"
             + "负载扭矩(M): " + (Math.Round(M * 10000) / 10000).ToString() + " Nm" + "\r\n"
             + "负载加速时产生的力(Fa): " + (Math.Round(Fa * 10000) / 10000).ToString() + " N" + "\r\n"
             + "齿轮节圆周长(L): " + (Math.Round(L * 10000) / 10000).ToString() + "\r\n"
             + "负载加速时产生的扭矩(Ma): " + (Math.Round(Ma * 10000) / 10000).ToString() + " Nm" + "\r\n"
             + "电机应有扭矩(M电): " + (Math.Round(MElec * 10000) / 10000).ToString() + " Nm" + "\r\n"
             + "电机应有惯量(J电): " + (Math.Round(JElec * 10000) / 10000).ToString() + " Kg.cm^2" + "\r\n"
             + "电机应有转速(n电): " + (Math.Round(nElec * 10000) / 10000).ToString() + " r/min" + "\r\n"
             + "电机应有转速(n电): " + (Math.Round(nElec * 10000) / 10000).ToString() + " r/min" + "\r\n"
             + "直线背隙,mm: " + (Math.Round(ZhiXian * 10000) / 10000).ToString() + "\r\n";
        }
        }
    }
}

在这里插入图片描述


之前出现问题

在这里插入图片描述
在下一次计算前把InPutNow1赋给了inPutBefore1,但当计算结束后,InPutNow1和inPutBefore1变成一样

原因
赋值赋的是地址,所以虽然值变了,但地址还是一样的,所以InPutNow1和inPutBefore1是一样的。
方法
inputBefore1 = (string [])inPutNow1.Clone();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值