Solved

it is safe to reduce my code like this??

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 36
Change data in datatable 8 29
update textboxes with Streamreader 21 42
Help with sorting data in Listbox using VB.NET 3 53
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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now