0

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);
        }
    }
}    
6
  • 2
    What is the error exactly? On which line? Your question is little bit unclear. Commented May 10, 2015 at 15:45
  • I believe that there is no error but that code is maybe incorrect. The Account number definitely exists however when I click the button I get the MessageBox to show up and if I comment out the else if statement nothing happens at all. Commented May 10, 2015 at 15:57
  • Have you stepped through it with the debugger? That would be the first thing to do - see what all the variables are and whether txtAccountNum.Text actually equals account.getAccountNumber(i) at any point. Commented May 10, 2015 at 16:04
  • I get the MessageBox to show up this seems to be improbable giving the fact the loop exits when i is equalt to Accounts. Unless you change this value inside the getAccountNumber, logInVerified or getBalance.... Commented May 10, 2015 at 16:12
  • Are you calling the operator ==(object, object) overload? It tests for reference equality (identical instances) only. The overload of == is statically (non-virtually) bound at compile-time. Commented May 10, 2015 at 16:23

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.