Hi I have the following code:
if (chkMaster.Checked)
{
dbFile = dbFile.Substring(0,dbFile.LastIndexOf(@"\")+1) + "master.mdb";
compactDatabase(ref testPassword, dbFile, userID, pword, regPath, systemFile);
if (!testPassword)
{
return;
}
progressBar.Value ++ ;
}
if (chkToolbox.Checked)
{
dbFile = dbFile.Substring(0,dbFile.LastIndexOf(@"\")+1) + "toolbox.mdb";
compactDatabase(ref testPassword, dbFile, userID, pword, regPath, systemFile);
if (!testPassword)
{
return;
}
progressBar.Value ++ ;
}
if (chkImport.Checked)
{
dbFile = dbFile.Substring(0,dbFile.LastIndexOf(@"\")+1) + "Import.mdb";
compactDatabase(ref testPassword, dbFile, userID, pword, regPath, systemFile);
if (!testPassword)
{
return;
}
progressBar.Value ++ ;
}
if (chkUser.Checked)
{
dbFile = dbFile.Substring(0,dbFile.LastIndexOf(@"\")+1) + "User.mdb";
compactDatabase(ref testPassword, dbFile, userID, pword, regPath, systemFile);
if (!testPassword)
{
return;
}
progressBar.Value ++ ;
}
if (chkImpData.Checked)
{
dbFile = dbFile.Substring(0,dbFile.LastIndexOf(@"\")+1) + "ImpData.mdb";
compactDatabase(ref testPassword, dbFile, userID, pword, regPath, systemFile);
if (!testPassword)
{
return;
}
progressBar.Value ++ ;
}
As can be seen the code is quite repetitive, is there some way to reduce
this code by maybe calling a method? CheckBoxes are checked to select which
database to compact. Would it be better to loop throught these somehow rather
than using all the if statements?
Thanks