473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Reducing Code

Hi, I have the following method which contains some repeated code. Could this
be reduced somehow? Thanks.

private void chooseDatabase()
{
string dbFile = GetPath();
string systemDB = GetSystemDB();
try
{
if (File.Exists(systemDB))
{
string UserID = GetUser();
string Pwd = GetPwd();
progressBar.Value = 1 ;
bool testPassword = true;
if (chkMaster.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Master.mdb");
if (!testPassword)
return;
if (chkToolbox.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Toolbox.mdb");
if (!testPassword)
return;
if (chkImport.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Import.mdb");
if (!testPassword)
return;
if (chkLibrary.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "Library.mde");
if (!testPassword)
return;
if (chkUser.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "User.mdb");
if (!testPassword)
return;
if (chkImpData.Checked)
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword, "ImpData.mdb");
if (!testPassword)
return;
progressBar.Value = progressBar.Maximum;
MessageBox.Show("Compacting complete.",messageHeader);
}
else
//Cannot find System database file
{
MessageBox.Show("Cannot find the System database " + systemDB + "\n" + "\n" +
"Check the database name (and path, if specified) to make sure it exists.",
messageHeader,MessageBoxButtons.OK,MessageBoxIcon. Exclamation);
progressBar.Value = progressBar.Minimum;
}
}
catch (System.Security.Cryptography.CryptographicExcepti on)
{
//System Database User Name corrupt
MessageBox.Show("System database is corrupt." + "\n" + "\n" +
"Replace the file " + systemDB + ".",
messageHeader,MessageBoxButtons.OK,MessageBoxIcon. Exclamation);
}
}
Nov 16 '05 #1
1 1201
Hi, I have the following method which contains some repeated code. Could this
be reduced somehow?


CheckBox[] checkBoxes = {chkMaster, chkToolbox, chkImport, chkLibrary,
chkUser, chkImpData};
string[] databases = {"Master.mdb", "Toolbox.mdb", "Import.mdb",
"Library.mdb", "User.mdb", "ImpData.mdb"};

....

for ( int i = 0; i < checkBoxes.Length; i++ ) {
if ( checkBoxes[i].Checked )
CompactDB(dbFile, systemDB, UserID, Pwd, ref testPassword,
databases[i]);
if (!testPassword)
return;
}

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Peter Salzman | last post by:
Hi all, Newish PHP programmer here. I wrote a form select class to help reduce code clutter, but I don't think the effort was worth it. I was hoping to post my attempt and get some ideas from...
15
by: Ralf W. Grosse-Kunstleve | last post by:
****************************************************************************** This posting is also available in HTML format: http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html...
5
by: Salvador I. Ducros | last post by:
Greetings all, I was hoping someone might be able to point me in the right direction. I'm currently using std::vector to maintain several lists whose objects are of unrelated types (classes)....
12
by: Stuart MacMartin | last post by:
Looking for tricks for speeding up builds... We have an application with about 970 of our own classes of various sizes plus a fair number of routines. Over the past year the compile/link time...
0
by: Filipe Martins | last post by:
Hello to all. Ever had a problem when your print some reports in a printer other the one you use more frequently, in which the report width span more tban one page? I did, and didn't liked it. ...
6
by: John Wood | last post by:
As everybody points out, the best way to reduce the memory footprint of a ..net application is to minimize it and restore it. This can make my app go from 40Mb of usage to about 3Mb of usage. Of...
8
by: Greg Merideth | last post by:
I've written a basic windows service to provide some helper xml functions for my web methods and even thou the service is only about 1k lines long with 1 timer, its mem usage is 10m and its vm mem...
0
by: foldface | last post by:
Hi Anyone got any general tips on reducing complexity on 'bigish' pages? I'm thinking here of a page with a number of usercontrols, all posting back, dynamic controls being added, having...
4
by: Patrick | last post by:
I have a tablespace that contains the LOB data for 3 tables which exist in other tablespaces. Even after reorging the LOB tablespace with the LONG option, the high water mark is still too high. I...
4
by: d0ugg | last post by:
Hello everyone, I'm creating a program that it is suppose to add, subtract, multiply and also divide fractions and after that, the result has to be reduced to the lowest terms. However, I'm not...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.