OPsteffOP OPsteffOP - 2 months ago 6
C# Question

C# variable won't change?

(Everything is made in C#)
The

loggedIn
variable in the
MainWindow
class won't change to
true
?
The
label
will change but the variables won't.
How can I fix this? Thanks for helping me!

MainWindow game = new MainWindow();

if(!game.loggedIn)
{
if (tbxUsername.Text != "" && tbxPassword.Text != "")
{
if(System.IO.File.Exists(System.AppDomain.CurrentDomain.BaseDirectory + "Passwords\\" + tbxUsername.Text + ".txt"))
{
if(System.IO.File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory + "Passwords\\" + tbxUsername.Text + ".txt") == tbxPassword.Text)
{
game.loggedIn = true;
game.username = tbxUsername.Text;
game.password = tbxPassword.Text;
lblMessage.Content = "U bent ingelogd als " + game.username + "!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
else
{
lblMessage.Content = "U heeft een verkeerd password ingegeven!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
}
else
{
lblMessage.Content = "Deze username bestaat niet!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
}
else
{
lblMessage.Content = "U heeft geen password / username ingegeven!";
tbxUsername.Text = "";
tbxPassword.Text = "";
}
}
else
{
lblMessage.Content = "U bent al ingelogd!";
}


}

Answer

Don't have the wider scope of the code but I'm pretty sure the problem is that you initialize a new MainWindow each time this function is called