Mojomancer
Mojomancer

Reputation: 21

C# if statement comparing text to array

Account Numbers are 6 digits in length when inserted into the array. They are stored as strings 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);
        }
    }
}    

Upvotes: 0

Views: 68

Answers (1)

Mojomancer
Mojomancer

Reputation: 21

I forgot to declare my arrays as static. Fixed now, thanks for all the help guys :)

Upvotes: 1

Related Questions