473,324 Members | 2,313 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,324 software developers and data experts.

reusing Code

I have some code that is exactly the same except for 1 name.

In the "for loops" below the 2nd parameters change as they are pointing to
separate string arrays in the structure:

nhDataBean.benefitGroupCodeList.GetUpperBound(0)
nhDataBean.jobCodeList.GetUpperBound(0)

************************************************** *************
public DataTable GetBenefits()
{
int ktr1 = 0;
DataTable dt = new DataTable();
DataRow dr;
// Add the columns to the DataTable's Columns collection
dt.Columns.Add("code");
dt.Columns.Add("description");

for (ktr1=1;ktr1<=nhDataBean.benefitGroupCodeList.GetU pperBound(0);ktr1++)
{
dr = dt.NewRow();
dr["code"] = nhDataBean.benefitGroupCodeList[ktr1][0];
dr["description"] = nhDataBean.benefitGroupCodeList[ktr1][1];
dt.Rows.Add(dr);
}
return dt;
}

public DataTable GetJobTitles()
{
int ktr1 = 0;
DataTable dt = new DataTable();
DataRow dr;
// Add the columns to the DataTable's Columns collection
dt.Columns.Add("code");
dt.Columns.Add("description");

for (ktr1=0;ktr1<=nhDataBean.jobCodeList.GetUpperBound (0);ktr1++)
{
dr = dt.NewRow();
dr["code"] = nhDataBean.jobCodeList[ktr1][0];
dr["description"] = nhDataBean.jobCodeList[ktr1][1];
dt.Rows.Add(dr);
}
return dt;
}
************************************************** ********************

There are about 10 of these in the structure.

Is there a way to pass this into one function change the for loop to use the
variable passed in?

Thanks,

Tom
Mar 14 '06 #1
2 1385
On Mon, 13 Mar 2006 16:19:16 -0800, "tshad" <ts**********@ftsolutions.com>
wrote:
I have some code that is exactly the same except for 1 name.

In the "for loops" below the 2nd parameters change as they are pointing to
separate string arrays in the structure:

nhDataBean.benefitGroupCodeList.GetUpperBound(0)
nhDataBean.jobCodeList.GetUpperBound(0)

************************************************* **************
public DataTable GetBenefits()
{
int ktr1 = 0;
DataTable dt = new DataTable();
DataRow dr;
// Add the columns to the DataTable's Columns collection
dt.Columns.Add("code");
dt.Columns.Add("description");

for (ktr1=1;ktr1<=nhDataBean.benefitGroupCodeList.GetU pperBound(0);ktr1++)
{
dr = dt.NewRow();
dr["code"] = nhDataBean.benefitGroupCodeList[ktr1][0];
dr["description"] = nhDataBean.benefitGroupCodeList[ktr1][1];
dt.Rows.Add(dr);
}
return dt;
}

public DataTable GetJobTitles()
{
int ktr1 = 0;
DataTable dt = new DataTable();
DataRow dr;
// Add the columns to the DataTable's Columns collection
dt.Columns.Add("code");
dt.Columns.Add("description");

for (ktr1=0;ktr1<=nhDataBean.jobCodeList.GetUpperBound (0);ktr1++)
{
dr = dt.NewRow();
dr["code"] = nhDataBean.jobCodeList[ktr1][0];
dr["description"] = nhDataBean.jobCodeList[ktr1][1];
dt.Rows.Add(dr);
}
return dt;
}
************************************************* *********************

There are about 10 of these in the structure.

Is there a way to pass this into one function change the for loop to use the
variable passed in?

Thanks,

Tom

Yes you can. Just substitute your variable(s) in the appropriate places.

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
Mar 14 '06 #2
Identify the elements in the code which are different for each usage, and
create a function that takes these elements as parameters.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer

Presuming that God is "only an idea" -
Ideas exist.
Therefore, God exists.

"tshad" <ts**********@ftsolutions.com> wrote in message
news:eZ**************@tk2msftngp13.phx.gbl...
I have some code that is exactly the same except for 1 name.

In the "for loops" below the 2nd parameters change as they are pointing to
separate string arrays in the structure:

nhDataBean.benefitGroupCodeList.GetUpperBound(0)
nhDataBean.jobCodeList.GetUpperBound(0)

************************************************** *************
public DataTable GetBenefits()
{
int ktr1 = 0;
DataTable dt = new DataTable();
DataRow dr;
// Add the columns to the DataTable's Columns collection
dt.Columns.Add("code");
dt.Columns.Add("description");

for (ktr1=1;ktr1<=nhDataBean.benefitGroupCodeList.GetU pperBound(0);ktr1++)
{
dr = dt.NewRow();
dr["code"] = nhDataBean.benefitGroupCodeList[ktr1][0];
dr["description"] = nhDataBean.benefitGroupCodeList[ktr1][1];
dt.Rows.Add(dr);
}
return dt;
}

public DataTable GetJobTitles()
{
int ktr1 = 0;
DataTable dt = new DataTable();
DataRow dr;
// Add the columns to the DataTable's Columns collection
dt.Columns.Add("code");
dt.Columns.Add("description");

for (ktr1=0;ktr1<=nhDataBean.jobCodeList.GetUpperBound (0);ktr1++)
{
dr = dt.NewRow();
dr["code"] = nhDataBean.jobCodeList[ktr1][0];
dr["description"] = nhDataBean.jobCodeList[ktr1][1];
dt.Rows.Add(dr);
}
return dt;
}
************************************************** ********************

There are about 10 of these in the structure.

Is there a way to pass this into one function change the for loop to use
the variable passed in?

Thanks,

Tom

Mar 14 '06 #3

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

Similar topics

2
by: Jo Voordeckers | last post by:
Hello all, I'm pretty new to the Java newsgroups so I apologize for dropping this into several maybe offtopic groups. I'm sorry! So on to my problem... I've come to a point in our RMI...
0
by: Oleg Paraschenko | last post by:
Hello, I'd like to introduce an article which might be of some interest: Reusing XML Processing Code in non-XML Applications HTML: http://uucode.com/texts/genxml/genxml.html PDF: ...
0
by: Mike | last post by:
Greetings, I have a COM+ component whose integrity I would like to maintain. In other words, I do not want to rebuild it in the .net environment. How do I go about reusing the DLL in a .net...
9
by: Alan | last post by:
Using VC++ (1998) compiler with PFE32 editor in Win2K Pro SP4. (DigitalMars CD on order. ) The program (below) instantiates a class and then deletes it. I would have thought that reusing the...
7
by: Klaus Johannes Rusch | last post by:
Is the following code valid and supported by current implementations? function somename() { this.show = function () { document.write("somename called") } } var somename = new somename();...
4
by: Old Wolf | last post by:
#include <stdio.h> #include <stdarg.h> Is this safe: void foo(const char *fmt, ...) { va_list ap; va_start(ap,fmt);
2
by: Andy Fish | last post by:
Hi, With languages like c# having namespaces, I was wondering what's the recommended practice for reusing source code. I'm not talking big stuff like log4net that's version controlled and...
3
by: Vik | last post by:
I use the same dataadapters and datasets on a few aspx pages. Currently I create these data controls on each page. Is it possible to create these controls only once and then use them on the...
7
by: Zodiac | last post by:
Hi all, I've been studying ASP.Net for a couple of weeks now.And it's starting to come to me. For me the next step is trying to figure out what is the best way to reuse code and webforms. For...
3
by: garyusenet | last post by:
Dear Professionals, I have recently been using the wonderful krypton toolkit and am trying to use them in my small hobby application. I include this bit of info as an aside really because i'm...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.