Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

it is safe to reduce my code like this??

Posted on 2013-01-05
2
Medium Priority
?
251 Views
Last Modified: 2013-01-05
I would like to know if it is safe or it is same thing if I change this code from this:
'NORMAL CODE'
    Private Sub rec_agua21_basep3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rec_agua21_basep3.CheckedChanged
        If rec_agua21_basep3.Checked = True Then
            paso_medio("p3", "base", "tb")
            paso_medio("p3", "base", "tv2005")
        End If
    End Sub

    Private Sub rec_agua22_basep3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rec_agua22_basep3.CheckedChanged
        If rec_agua22_basep3.Checked = True Then
            paso_medio("p3", "base", "tb")
            paso_medio("p3", "base", "tv2005")
        End If
    End Sub
    Private Sub temp_calentamiento_basep3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles temp_calentamiento_basep3.CheckedChanged
        If temp_calentamiento_basep3.Checked = True Then
            paso_medio("p3", "base", "tb")
            paso_medio("p3", "base", "tv2005")
        End If
    End Sub

    Private Sub rec_agua21_secp3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rec_agua21_secp3.CheckedChanged
        If rec_agua21_secp3.Checked = True Then
            paso_medio("p3", "sec", "tb")
            paso_medio("p3", "sec", "tv2005")
        End If
    End Sub

    Private Sub rec_agua22_secp3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rec_agua22_secp3.CheckedChanged
        If rec_agua22_secp3.Checked = True Then
            paso_medio("p3", "sec", "tb")
            paso_medio("p3", "sec", "tv2005")
        End If
    End Sub

    Private Sub temp_calentamiento_secp3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles temp_calentamiento_secp3.CheckedChanged
        If temp_calentamiento_secp3.Checked = True Then
            paso_medio("p3", "sec", "tb")
            paso_medio("p3", "sec", "tv2005")
        End If
    End Sub

Open in new window


To this:
'REDUCE CODE'
    Private Sub seccion1_p3(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rec_agua21_base_p3.CheckedChanged, rec_agua22_base_p3.CheckedChanged,  temp_calentamiento_base_p3.CheckedChanged, rec_agua21_sec_p3.CheckedChanged, rec_agua22_sec_p3.CheckedChanged,  temp_calentamiento_sec_p3.CheckedChanged
        Dim pruebas() As String
        pruebas = Split(DirectCast(sender, Control).Name, "_")
        If DirectCast(sender, RadioButton).Checked = True Then
            paso_medio(pruebas(3), pruebas(2), "tb")
            paso_medio(pruebas(3), pruebas(2), "tv2005")
        End If
    End Sub

Open in new window

0
Comment
Question by:altariamx2003
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 38748023
I do that kind of thing all the time.  It's "safe" as long as you ensure that all controls entering that handler will fit the constraints of the code.  You could always add in error checking.  I'd rather put that kind of code in one place as you've done, since any changes would be immediately applied to all the controls affected, and you don't have to manually change a bunch of separate handlers.
0
 

Author Comment

by:altariamx2003
ID: 38748026
ok

thanks idle_mind
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question