473,326 Members | 2,099 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,326 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 1241
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: 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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.