Solved

it is safe to reduce my code like this??

Posted on 2013-01-05
2
247 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

622 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