how 2 exit a program when user enters wrong password and username 3 tyms

Hi, can anybody help me with creating some sort of while loop for my program, when a user enters an incorrect username and password 3 times I want the program to end. I have tried all sorts but I can't seem to get it right. Please take a look at my code below thanks.

private: System::Void btnLogin_Click(System::Object^ sender, System::EventArgs^ e)
{
// validate input
if (!ValidateInput())
return;

// connect to database to check username and password
try {
// create an instance of class DbAccess
DbAccess ^ db = gcnew DbAccess();

// definition of variables
String ^userName = txtUserName->Text->Trim();// 'Trim' removes all white space
String ^password = txtPassword->Text->Trim();


// wrong username and password combination
if (!db->Verify(userName, password))
{
ViewMessage("Incorrect username and password combination!");


// clear text boxes
txtPassword->Text = "";
txtUserName->Text = "";

// focus to user text box
txtUserName->Focus();
return;
}
else { // correct user and password

// dialog result is ok so close form
this->DialogResult = System::Windows::Forms::DialogResult::OK; this->Close();

/* opens application - tells the complier what to do i.e execute window and tells it which path to take.
The WinExec() function takes two arguments, the first one specifies the location or
Command Line of the executable file or application, the second one specifies how the window
will be displayed when the application starts*/

//WinExec("C:\\Program Files (x86)\\Windows Live\\Messenger\\msnmsgr.exe", SW_NORMAL);
WinExec("C:\\Program Files (x86)\\EasyBits For Kids\\ezDesktop.exe Desktop",SW_NORMAL);
//WinExec("C:\\Windows\\System32\\mstsc.exe",SW_NORMAL);
}
}

// catch thrown exception - represents errors that occur during application execution
catch (Exception ^ex)

{
//gets message that desribes the current exception
ViewMessage(ex->Message);
}
}
Topic archived. No new replies allowed.