So the thing is, I made a timer1_Tick, and within that, I.. I'll show you a less cluttered example, and then the actual code.
The less cluttered example:
void timer1_Tick(object sender, EventArgs e)
{
if (textBox1.Text.Contains("specific text"))
{
textBox1.Text = "Try again";
timer1.Enabled = false; //I was under the impression that this would stop it from running again
}
else
{
textBox1.Text = "Another text";
timer1.Enabled = false;
}
}
So there, I had hoped that if it goes into the if, and runs that, that timer1.Enabled = false; would stop it from running after it runs the if part and only the if part. And it does, for the first time. However the second time I enter an invalid value, it runs the main if, and then it goes back into the void and runs the else part. And I have no idea what causes it.
A brief clarification of what I'm doing in the real code that causes the error:
I enter an account number, and a pin number. Both of those I leave blank, so both of those values will become null. It (the client) then sends the values to the server, and the server sends back the reply: "Either the account number or pin number was invalid".
And when this happens, I start running the timer1_Tick, and seeing as the if checks the textBox for the word invalid, what I wanted it to do, was to change the text in the textBox (among other things) and then the timer1.Enabled = false was supposed to stop running the timer, and definitely not run the else part.
How it actually works:
The first time I enter a null and null for both the acc and the pin, it does exactly that.
However, the second time I do that (in a row) it runs the if part and then carries on to run the else part and I have no idea why.
So erm, can anyone tell what I'm doing wrong from the code below?
void timer1_Tick(object sender, EventArgs e)
{
if (textBox1.Text.Contains("invalid")) //If the user received an "invalid login" message from the server, it should appear in the textbox and so the part below runs
{
accountNumer = null; //Reset the accountNumber variable
pinNumer = null; //Reset the pinNumber variable
textBox1.Text = "Welcome!\r\nPlease enter your account number: " + accountNumer + "\r\nEnter your pin number: " + pinNumer; //Displays a welcome message in the textBox and asks for the user's account and pin number again
teljari = 0;
timer1.Enabled = false; //This should shut down the timer, or so I thought
}
else //If the user does NOT get the invalid login message, this will display the main menu
{
textBox1.Text = "Main Menu\r\n 1 - View my balance\r\n 2 - Withdraw Cash\r\n 3 - Deposit funds\r\n 4 - Exit";
timer1.Enabled = false;
}
}

New Topic/Question
Reply



MultiQuote






|