Solved

it is safe to reduce my code like this??

Posted on 2013-01-05
2
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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