Hello :icon_neutral:

I am doing a test to return payment details - but seem to be having a problem with the card number. When I run the code below I get an error saying that it is too large or small to be an integer.

If I make the variable a float the info is returned but it is a silly number with decimal point and plus signs in it !

Is there an obvious way around this please - or am I doing something else wrong:-/

Thank you ... John.

private void btnExecutePayment_Click(object sender, EventArgs e)
        {
            m_CustomerName = txtNameOnCard.Text; ;
            m_CardNumber = int.Parse(txtCardNumber.Text);
            m_StartDate = txtStartDate.Text;
            m_EndDate = txtEndDate.Text;
            m_SecurityCode = int.Parse(txtSecurityCode.Text);
            
            DateTime startDate = DateTime.Parse(txtStartDate.Text);
            DateTime endDate = DateTime.Parse(txtEndDate.Text);

            try
            {

                if (string.IsNullOrEmpty(txtNameOnCard.Text)) //if (txtNameOnCard.Text == string.Empty)
                {
                    NameOnCardEP.SetError(txtNameOnCard, "Please enter a name");// if empty
                }
                else
                {
                    NameOnCardEP.Clear();//if empty clear
                }

                if (string.IsNullOrEmpty(txtCardNumber.Text)) //if (txtCardNumber.Text == string.Empty)
                {
                    CardNumberEP.SetError(txtCardNumber, "Please enter a card number");
                }
                else
                {
                    CardNumberEP.Clear();
                }

                if (txtCardNumber.Text.Length < 16 || txtCardNumber.Text.Length > 16)//has to be 16
                {
                    MessageBox.Show("The card number must be sixteen digits long ", "CARD NUMBER ERROR ");
                }

                if (string.IsNullOrEmpty(txtStartDate.Text)) //if (txtStartDate.Text == string.Empty)
                {
                    StartDateEP.SetError(txtStartDate, "Please enter a start date");
                }
                else
                {
                    txtStartDate.Clear();
                }

                if (string.IsNullOrEmpty(txtCardNumber.Text)) //if (ECenterPostcodeTextBox.Text == string.Empty)
                {
                    EndDateEP.SetError(txtEndDate, "Please enter an end date");
                }
                else
                {
                    EndDateEP.Clear();
                }

                if ((startDate) > (endDate)) //if (ECenterPostcodeTextBox.Text == string.Empty)
                {
                    MessageBox.Show("The card start date can not be more than the card end date ", "CARD DATE ERROR ");
                    txtStartDate.Clear();
                    txtEndDate.Clear();
                }
                if (string.IsNullOrEmpty(txtCardNumber.Text)) //if (ECenterPostcodeTextBox.Text == string.Empty)
                {
                    SecurityCodeEP.SetError(txtSecurityCode, "Please enter a security code");
                }
                else
                {
                    SecurityCodeEP.Clear();
                }
                if (txtSecurityCode.Text.Length < 3 || txtSecurityCode.Text.Length > 3)
                {
                    MessageBox.Show("The security code must be three digits long ", "SECURITY CODE ERROR ");
                    txtSecurityCode.Clear();
                }

                MessageBox.Show(" Name on card:  " + m_CustomerName + "\r\n" + " Card Number: " + m_CardNumber + "\r\n" + " Start Date:  " + m_StartDate + "\r\n" + " End Date:" + m_EndDate + "\r\n" + " Security Code:  " + m_SecurityCode, "PAYMENT TEST DATA");
              

            }

You are trying to hold a number in 'm_CardNumber' that is too large...

use a 'long(int64)' instead, this should solve your problem.

commented: Thank you +2

Since when is a card number an integer? What would you calculate with it?
Leave it as a string.

commented: Great advice +2

Since when is a card number an integer? What would you calculate with it?
Leave it as a string.

Ahhhh:$ hhahaha ... thanks ... I didn't think of that!

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.