You probably hear this 1000's of times but I am getting this error. All I am trying to do is pass yardage to the topRow class but it turns to 0 by the time it gets there. Any ideas?

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;
using FootballPracticum;

namespace FootballPracticum
{
    public partial class PlayCall : Form
    {
        Int16 yardage;
        public PlayCall()
        {
            InitializeComponent();
        }//end constructor

        private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        public void btnSubmitPlay_Click(object sender, EventArgs e)
        {
            yardage = Convert.ToInt16(txtYardResult.Text);
            topRow start = new topRow();
            theDown.Text = Convert.ToString(start.setDown());
            theDistance.Text = Convert.ToString(start.setDistance());
            fieldPosition.Text = Convert.ToString(start.yardLine());
            time.Text = Convert.ToString(txtTime.Text);
        }//end button click

        public Int16 getYardage
        {
            get
            {
                return yardage;
            }//end get
            set
            {
                yardage = Convert.ToInt16(txtYardResult.Text);
            }//end set
        }//end setYardage
     }//end Playcall 
   }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FootballPracticum
{
    public class topRow 
     {
    public Int16 down;
    public Int16 spotOnField;
    public Int16 toGo;
    public Int16 yardResult;

    public topRow()
    {
        PlayCall now = new PlayCall();
        frmNewSeries setter = new frmNewSeries();
        yardResult = now.getYardage;

    }//end constructor

    public Int16 setDown()
    {
        if (yardResult >= toGo)
        {
            down = 1;
            return down;
        }//end if
        else
        {
            down = Convert.ToInt16(down + 1);
            return down;
        }//end else
    }//end setDown

    public Int16 setDistance()
    {
        if (yardResult >= toGo)
        {
            toGo = 10;
            return toGo;
        }//end if
        else
        {
            toGo = Convert.ToInt16(toGo - yardResult);
            return toGo;
        }//end else

    }//endsetDistance

    public Int16 yardLine()
    {
        spotOnField = Convert.ToInt16(spotOnField + yardResult);
        return spotOnField;
    }//end fieldPosition
}//end topRow Class
}//end Namespace

Use Int16.TryParse method instead of Convert.ToInt16,

For example,

Int16.TryParse(txtYardResult.Text, out yardage);

Use Int16.TryParse method instead of Convert.ToInt16,

For example,

Int16.TryParse(txtYardResult.Text, out yardage);

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.