dimanche 10 mai 2015

C# if statement comparing text to array

first time posting here. I have been trying to get this to work for the last 3 hours and I always end up with the same lines of code.

Account Numbers are 6 digits in length when inserted into the array. They are stored as a string as they can begin with a 0.

As an example, I always use the Account Number of 123456 however when I put that in the TextBox and click btnLogIn it gives me an error.

logInVerified is a method that will show or hide another text box depending on the users input.

private void btnLogIn_Click(object sender, EventArgs e)
    {

        for (int i = 0; i < account.Accounts; i++)
        {
            if (txtAccountNum.Text == account.getAccountNumber(i))
            {
                logInVerified(true);
                txtBalance.Text = Convert.ToString(account.getBalance(i));
            }
           else if (i == account.Accounts)
            {
                MessageBox.Show("No account found, please check Account and PIN numbers and try again.", "No account found", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

Any help is appreciated, thanks for taking time to read :)

Aucun commentaire:

Enregistrer un commentaire