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

Overloads - DRY

Hi All

How can I recode the following so that I do not repeat my
code?

Public Overloads Sub SetNodeImageIndex(ByVal oNode As
System.Windows.Forms.TreeNode, ByVal ImageIndex As String)

oNode.ImageIndex = ImageIndex
oNode.SelectedImageIndex = ImageIndex

End Sub

Protected Overloads Sub SetNodeImageIndex(ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs, ByVal
ImageIndex As Long)

e.Node.ImageIndex = ImageIndex
e.Node.SelectedImageIndex = ImageIndex

End Sub

regards, valamas
Jul 21 '05 #1
2 1245
Valamas

You cannot when you use both

Cor
Jul 21 '05 #2
"valamas" <an*******@discussions.microsoft.com> wrote:
Hi All

How can I recode the following so that I do not repeat my
code?

Public Overloads Sub SetNodeImageIndex(ByVal oNode As
System.Windows.Forms.TreeNode, ByVal ImageIndex As String)

oNode.ImageIndex = ImageIndex
oNode.SelectedImageIndex = ImageIndex

End Sub

Protected Overloads Sub SetNodeImageIndex(ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs, ByVal
ImageIndex As Long)

e.Node.ImageIndex = ImageIndex
e.Node.SelectedImageIndex = ImageIndex

End Sub

regards, valamas


I must be missing something because the obvious DRY (Do not
Repeat Yourself) solution is:

Public Overloads Sub SetNodeImageIndex( _
ByVal oNode As System.Windows.Forms.TreeNode, _
ByVal ImageIndex As String _
)
' Delegate actual work to one common method
SetNodeImageIndexCommon(oNode, CInt(ImageIndex))
End Sub

Protected Overloads Sub SetNodeImageIndex( _
ByVal e As System.Windows.Forms.TreeViewCancelEventArgs, _
ByVal ImageIndex As Long _
)
' Delegate actual work to one common method
SetNodeImageIndexCommon(e.Node, CInt(ImageIndex))
End Sub

Private Sub SetNodeImageIndexCommon( _
ByVal oNode As System.Windows.Forms.TreeNode, _
ByVal ImageIndex As Integer _
)
' Do actual work in only one place
oNode.ImageIndex = ImageIndex
oNode.SelectedImageIndex = ImageIndex
End Sub
Or even
Public Overloads Sub SetNodeImageIndex( _
ByVal oNode As System.Windows.Forms.TreeNode, _
ByVal ImageIndex As String _
)
' Do actual work in only one place
oNode.ImageIndex = CInt(ImageIndex)
oNode.SelectedImageIndex = CInt(ImageIndex)
End Sub

Protected Overloads Sub SetNodeImageIndex( _
ByVal e As System.Windows.Forms.TreeViewCancelEventArgs, _
ByVal ImageIndex As Long _
)
' Delegate actual work to one common method
SetNodeImageIndex(e.Node, CStr(ImageIndex))
End Sub
'Any fool can write code that a computer can understand.
Good programmers write code that humans can understand.'
Martin Fowler,
'Refactoring: improving the design of existing code', p.15
Jul 21 '05 #3

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

Similar topics

59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
12
by: Lee Silver | last post by:
In a base class I have the following 2 declarations: Overridable Sub Remove(ByVal wIndex As Integer) and Overridable Sub Remove(ByVal wValue As Object) In an immediately derived class I...
10
by: Atif | last post by:
Hi I am here to solve a small confusion i have in "Overloads Overrides". "Overloading" says that the method's name should be same while no. of parameters and/or their datatypes should be changed...
5
by: Laurent Allardin | last post by:
Hi, Why this code compile??? We should not be able to Override the code by using the Overloads since the sub as exactly the same parameters.... Thank you. Laurent Allardin,MCSD,MCAD
4
by: Gary Paris | last post by:
Why would you use an Overloads routine instead of just putting the code in the default routine? Private Overloads Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As...
2
by: valamas | last post by:
Hi All How can I recode the following so that I do not repeat my code? Public Overloads Sub SetNodeImageIndex(ByVal oNode As System.Windows.Forms.TreeNode, ByVal ImageIndex As String) ...
3
by: Arthur Dent | last post by:
Hi all, Im just curious, what is the purpose of the keyword "Overloads" in VB nowadays? I understand conceptually what overloads are and what they do, but im a little puzzled, because if you...
12
by: André | last post by:
Hi, i'm learning working with classes. In class "classbase1", i defined an overridable function. In the class "subclass1", i defined the same function with 'Overrides'. In class "classbase2", i...
2
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
In the class below, I inherit from Generic.Dictionary so I can override property Item. Item is not overridable, so I used Shadows, and it works as I want. It works equally well if I replace...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.