[2008] Reducing The Code Duplication?

Mar 2, 2009

Reading through "The Pragmatic Programmer", I've come across the DRY (Don't Repeat Yourself) and Orthagonal (keep code modular) principles.I have a suite of modules, some of which have common procedures. Because each module is a separate project in Visual Studio, up until now I have simply copied code from one project to another when 1 module (project) needs to do the same function as another module (project). This is when functionality overlaps, not when 2 modules (projects) do everything the same.

I always suspected this was bad practice (and have seen the fruits of my suspicions when the subs get out of sync), and the book confirmed me in this belief. So, what I want to do is make a central code repository for the 4 or 5 common subs, but I don't know how to do it.Should I make a .dll file for each sub I want to use in multiple places? If so, how do I do that? Is there another way to do what I want to do?

1. I have a subroutine that takes a filepath (and if disconnected also a SqlConnection) and loads the referenced file into a database as a BLOB.

2. I have 3 separate projects in 1 VS solution that all run basically the same version of this code.

3. I want all 3 to run EXACTLY the same code.

4. I want 1 version of this code so that any changes made don't need to be made in 3 places.

5. I have a few other instances like this for other subroutines.

View 8 Replies


ADVERTISEMENT

If Statement Efficiency - Reducing The Code ?

May 27, 2011

How would you go about reducing the code for this but still allowing it to work the way it is now

Dim updatelesson As String = cmbChange.SelectedIndex
Dim chosenlesson As String = cmbSession.SelectedIndex
Dim changed As String = lstNames.SelectedItem

[CODE]....

View 3 Replies

Refactor To Remove Code Duplication?

Feb 1, 2011

This is a simplified version of a class that I have in my project. Since the Bonus is figured the exact same way in each function I want to remove the obvious code duplication that appears here and make the three different functions into one. However I am not sure how to provide the argument that this new function would require.

For instance I am currently just passing the argument like this from code

lblVolumeBonus.Content = TestClass.VolumeBonusAmountStore(bonus).

I think I have to basically turn this logic around and call it with something like

lblVolumeBonus.Content = TestClass.VolumeBonusAmountStore(BonusTrackerBO.StoreBonus)

but I am not sure of the correct syntax or whether I am on the right track at all.

Public Class TestClass
Public Shared Function StoreBonus(ByVal bonus As BonusTrackerBO.StoreBonus) As Double

[Code]....

Edit: It may not make a difference but I should have made clear that there are other factors in the equation (I was just trying to keep it simple). So is the answer the same when there are other callbacks to the bonus like bonus.MaximumAmount, bonus.MinimumAmount? There are 5 callbacks to the bonus object and the amounts are different depending on whether it is a Store, District or Company asking.

View 2 Replies

LINQ. Reducing The Code By Using Dynamic Queries?

Feb 17, 2011

I use the following code to fill the Table1 dictionary with the information found within the LINQ query.

Dim DB As New DatabaseDataContext
Dim Table1 As New Dictionary(Of String, Integer)
Dim Table2 As New Dictionary(Of String, Integer)

[code].....

View 3 Replies

Reducing .Net Code Using Inline Object Creation?

Apr 4, 2012

I have managed to crunch down a several line code to this

For Each gal In galleries
With New HtmlGenericControl("div")
.ID = gal.Header

[code]....

I cannot find any where how to reference back to the object i am currently working with to add the control back to galleryContent' - Using plain me crashes the whole web server...Using does not offer the shorter hand of just using . - But it Using the only way to do it?

View 3 Replies

Reducing Code Clutter When Using A ListViewItem Object

Aug 27, 2007

Reducing Code Clutter When Using A ListItem Object

When using ListItem objects, the normal procedure is as follows:

[Code]......

View 2 Replies

Code / Query That Will Prevent Duplication Of Data

Jun 5, 2011

i'm working on a voting system but im having problems in adding records... i have two a primary key, the idnumber and the address. the address is where I base if that certain address already voted. but the problem is everytime i try to add a record with the same address (ex. Block 1 lot 4), the data is duplicated which is not output i want. the program should detect that there is already an existing address.

[Code]...

View 3 Replies

VS 2008 Reducing Space Between Fonts?

Nov 6, 2010

Dim a as string = "a"
Dim b as string = "b"
Dim c as string = "c"

[code]....

View 11 Replies

VS 2008 Reducing The Size Of The Tabs On A Tab Control?

Jun 28, 2011

I noticed that when using a single letter as the title on a tab of a Tab Control , the tab is bigger that it should . Look on this example :

The above Tab Control behaves normally because the text on each tab is sufficient to keep it big enough . The lower Tab Control , however , has its tabs too big . Is it possible to reduce its width ? I saw there is an ItemSize property of the Tab Controls , but unfortunately I can only modify the height of the tabs . No matter what value I set for its width , the width remains always the same (and larger than it should) ...

View 4 Replies

VS 2008 Enlarging And Reducing Size Of A Circle Using Scrollbar

Nov 29, 2010

Im trying to enlarge a circle on a form using a scrollbar.I have managed to do this using the following [code]Thing is the code draws a circle on every scroll movement. You end up with a mass of circles. I want it to clear previous graphic and just show the circle that relates to the current scrollbar graphic, giving the impression of enlarging and shrinking.

View 3 Replies

VS 2008 - Updating Items In ListBox Without Duplication

May 17, 2010

If strCustomerOrder = "A1#" Then
decSubtotal = ANTACID_ONE
mintQuantity += 1
ShoppingCartForm.lstShoppingCart.Items.Add(("A1" & vbTab & vbTab & "Alka-Seltzer Antacid" _
[Code] .....
I want my listbox to not display duplicate items. I just want it to update the quantity(Qty).

View 2 Replies

VS 2008 : Making An Anti-file Duplication System For PC?

Oct 20, 2010

I was thinking of making a anti-file duplication system for my PC. I feel that i have a lot file duplicates so finding them would be nice.

View 12 Replies

Calculating GCF And Reducing

Jan 27, 2011

I understand the basics of using VB.NET, what I don't understand is what I need to tell the computer to do. I'm supposed to create a subprogram to calculate the greatest common factor and another subprogram to reduce the fraction from the answers retrieved from the first subprogram. My teacher said something about using Mod to calculate it, and also attempted and failed to explain ByVal and ByRef parameters. I don't even know where to begin other than the parameters I have for each, and even those have a high chance of being completely wrong.[code]

View 1 Replies

Reducing The Memory Usage?

Aug 30, 2009

I've been having complaints about my applications that they use to much memory.Is there a way to make them use less?

View 11 Replies

Sql Server - Reducing SQL Connections To Just 1 - ASP.net?

Feb 7, 2012

I am currently working on an asp.net web page with a GridView displaying a table from a database.This GridView has 4 DropDownLists that will be used to filter the data shown on the GridView. When the page loads 4 Sub routines are run, each one connecting to the database with a select statement to fill the DropDownList with relevant filter headings.

Initially, I had one connection with a loop that populated all of the drop downs but these contained duplicates. I then split the filling of each DDL so that the select statements could contain DISTINCT. I would like (and am sure there is a way here) to be able to populate all of the DDLs with data from one connection.

Code for one connection:

Protected Sub FillDepDDL()
Dim conn As New SqlConnection()
conn.ConnectionString =

[code]....

The other 3 column names: FirstName > DDLFN, LastName > DDLLN, Wage > DDLWag.This is only a test DB and the princibles learned here will be applied to a larger live project.

View 1 Replies

Duplication In A VB List Box

Mar 23, 2011

Using ASP/VB, I'm trying to get rid of some duplication in a list box that is coming from an XML document.[code]...

View 1 Replies

Reducing Strings To A Certain Length If They Are Longer?

Apr 27, 2009

I'm generating a list of names from my database, but I need to validate them so they are no longer than 15 characters.

Dim Name As String
Dim txtFirst = "../../Names/first.txt"
Dim txtLast = "../../Names/last.txt"

[Code]....

I need Name to be no longer than 15 characters, and it doesnt matter if the name stays in tact, it just needs to cut off characters from the end of the string until its 15 or less.

View 2 Replies

Reducing The Number Of Colors In An Image?

Dec 23, 2011

In the process of creating an Icon object, I need to reduce the numbers of colors in an image from thousands down to 256 or less. I do this by "chromatizing" the RGB values - counting the colors - then re-iterating the process with heavier "chromatization" until the number of colors is reduced to my requirement.

I searched these forums and google on this subject to find out more - but I found that I alone call this process "chromatization" it seems. So I was hoping someone could help me out with the correct terminology.

Specifically, I want to use the correct terminology on my UI buttons (at present I have a button labeled [Chromatize] . .) and I am curious as to whether it would be good practice to "chromatize" the Green most heavily, the Red more moderately, and the Blue least . . . or just "chromatize" them all equally which is what I have been doing

View 2 Replies

Reducing The Range Of A Bluetooth Device?

Oct 22, 2010

i am currently working on an application that reads the MAC addresses of all phones within the range of our bluetooth reader on the workstation. However, we would like to reduce the range of the reader to < 1 meter. I have dont alot of research and the only solution that i have found is a hardware one; i.e. changing the device to a class 3 or getting a custom made device that will have it's range adjusted to our preferences. However, i also know that we can adjust the power that runs through the bluetooth device in order to reduce the range. Is there any way that we can reduce the power of the device ? We don't have many funds atm and we're looking at a software solution and not a hardware one.

View 4 Replies

VS 2005 Reducing The Combo List?

Sep 14, 2010

I have a combo which contains a lot of different colours. If I press b it goes to the b's in the list and if I press it again it goes to the next b. Is it possible to jump to the colour as I type it so if I type blu it would go to blue. Currently it jumps to the first b when I type b but ignores the lu for blue.

View 4 Replies

Check For Duplication Before Insert?

Jan 13, 2009

In the below code I want to also check before inserting if that record exists or

Dim conn As New SqlConnection("xxxxx")
Try
conn.Open()

[code].....

View 1 Replies

Duplication Databinding.format In Wpf

Jun 19, 2009

Does anyone know how to duplicate the winforms databinding function - format in wpf? e.g. applying the format of #####0.00 to a text box?

View 3 Replies

Duplication Of Tabpage Layout?

Jul 21, 2010

I've gone through various thread, posts, classes and walkthroughs on sites but seem to be coming up short either in my understanding or what is/should be going on.I have a very simple data entry tabcontrol (think like microsoft excel but textboxes, labels and the odd combobox rather than a grid). When I click one tab it creates a new tab and names it according the sequence (no problems so far). Here is the crotch kicker (for me at least). I need the first tabpage layout on all additional tabpage so that data can be entered in each separately and stored with constant "processing" (adding and subtracting ).What would be the best approach to doing such a tabpage duplication?

Currently a User control library inheriting from tabpage seems like a good idea but with the 40 or so controls on it is this actually going to function like the first tabpage (as in the one i have now not the one I'd have if i used the user control instead).Do I take the raft of code the designer creates automatically for the tabpage and its controls and simply add them to the click event? Would this create duplication problems with name or would it be ok as they would be tabpage1.lblName and tabpage2.lblName?

View 4 Replies

How To Protect Project From Duplication

May 23, 2011

i developed a project using VB.Net 2005 and sql server 2005 standard edition at back end. now its complete and have to deliver to company now. but i am afraid that the company may reproduce a new copy of this software from the original and may sell to any other company or in open market. I want to implement some mechanism on my project for its security, which enables it to not to work on other computers or some similar type security.

View 3 Replies

Prevent Duplication In GridView?

May 30, 2010

I have this code and it is not working correctly. Note: The code must check the if the data is valid every time the user enters a new datai have 2 columns in my table

Code:
Private Sub Table_CellValidated(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellValidatedEventArgs) Handles Table.CellValidated

[code]....

View 2 Replies

Validate Duplication Of ID In Database?

Jun 12, 2011

I have a program connecting with a database.. so when add record in it, i want to validate for the duplication of ID in database..

here's my code for add button:
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
dSet.Tables(0).PrimaryKey = New DataColumn() {dSet.Tables(0).Columns("WatchID")} 'The table primary key is the WatchId

[Code]......

View 3 Replies

.net - Reducing Flicker When Change Images In A Panel?

May 4, 2009

How do I reduce flicker in a vb2005 panel?Inside the parent panel I have 2 other panels that I'm am using.

The outer most panel contains a background sprite and the two innermost panels are overlays that change to fit the places in the background sprite.When I change the overlay sprites I would like to reduce the flicker and make it a smooth transition from one sprite to the next.

Here is the code that changes the images in the overlay panels the overlay panel is not changed if the new value is the same as the old value

[Code]...

View 2 Replies

Asp.net - Reducing The ViewState Size On A Legacy System?

Jan 21, 2012

I've looked up ways to reduce the ViewState:

Viewstate Optimisations
Strategies for reducing ViewState size in asp.net

However, due to the situation I'm in, I need the quickest and most effective ways to reduce the ViewState size. The legacy system I'm working on is bloated and routinely has a ViewState that's 800Kb+ on multiple postbacks.

For example, I'm pretty sure populating drop down lists with 100+ items on multiple post backs is one of the culprits, correct?

Disabling the ViewStae entirely doesn't appear feasible. It breaks all of the controls, of which there are many, rendering the pages unusable. If this is the best approach, how should I go about handling all the broken controls?

View 4 Replies

Reducing A Dimension And Resolution Of A Picture Image?

Sep 6, 2009

<Visual Basic 2005 + SQL 2005>I am developing an Human Resource system that has to have a pictue image for each employee. I can't ask HR person that takes a picture and reduce it to upload to the HR system.

View 2 Replies

CD Collection Prevent User For Duplication

Nov 12, 2011

I'm writing a program on CD Collection. My problem is write a code that prevents a user to enter a CD collection name that is already stored in the filename.txt.

The rest of my program is okay, but the only problem is something do with btnAdd control.

Here's my whole program:

Option Explicit On
Option Strict On
Option Infer Off

[Code].....

View 14 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved