Solved

it is safe to reduce my code like this??

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

12 Experts available now in Live!

Get 1:1 Help Now