Solved

how I can optimize this code? if else

Posted on 2011-03-23
6
415 Views
Last Modified: 2012-05-11
hi experts, how I can optimize this code?
 
   If WFGDH.UI.Session.desicionSolicitud <> "NO" Then
                If WFGDH.UI.Session.varCodVicepresidencia.Equals("") Or WFGDH.UI.Session.varCodGCentral.Equals("") Or _
                        WFGDH.UI.Session.varCodDivision.Equals("") Or WFGDH.UI.Session.varCodDepartamento.Equals("") Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','NN');")
                ElseIf (WFGDH.UI.Session.varCodVicepresidencia.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Vp');")
                ElseIf (WFGDH.UI.Session.varCodGCentral.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Ce');")
                ElseIf (WFGDH.UI.Session.varCodDivision.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Dv');")
                Else
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Dp');")
                End If
            Else

                WFGDH.UI.Session.varCodVicepresidencia = WFGDH.UI.Session.SelUO
                WFGDH.UI.Session.varCodGCentral = WFGDH.UI.Session.SelUO
                WFGDH.UI.Session.varCodDivision = WFGDH.UI.Session.SelUO
                WFGDH.UI.Session.varCodDepartamento = WFGDH.UI.Session.SelUO

                If WFGDH.UI.Session.varCodVicepresidencia.Equals("") Or WFGDH.UI.Session.varCodGCentral.Equals("") Or _
                        WFGDH.UI.Session.varCodDivision.Equals("") Or WFGDH.UI.Session.varCodDepartamento.Equals("") Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','NN');")
                ElseIf (WFGDH.UI.Session.varCodVicepresidencia.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Vp');")
                ElseIf (WFGDH.UI.Session.varCodGCentral.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Ce');")
                ElseIf (WFGDH.UI.Session.varCodDivision.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Dv');")
                Else
                    btnNuevoColaborador.Attributes.Add("onclick", "javascript:return pCargarModal('Ascenso','N','-1','Dp');")
                End If

                WFGDH.UI.Session.varCodVicepresidencia = Nothing
                WFGDH.UI.Session.varCodGCentral = Nothing
                WFGDH.UI.Session.varCodDivision = Nothing
                WFGDH.UI.Session.varCodDepartamento = Nothing
            End If
0
Comment
Question by:enrique_aeo
  • 3
  • 2
6 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
>>  how I can optimize this code

Define "optimize".
0
 
LVL 13

Accepted Solution

by:
Rick earned 250 total points
Comment Utility
You could use SELECT CASE instead of IF THEN statements, and replace these lines:

WFGDH.UI.Session.varCodVicepresidencia = WFGDH.UI.Session.SelUO
WFGDH.UI.Session.varCodGCentral = WFGDH.UI.Session.SelUO
WFGDH.UI.Session.varCodDivision = WFGDH.UI.Session.SelUO
WFGDH.UI.Session.varCodDepartamento = WFGDH.UI.Session.SelUO

With these:

 With WFGDH.UI.Session
                .varCodVicepresidencia = WFGDH.UI.Session.SelUO
                .Session.varCodGCentral = WFGDH.UI.Session.SelUO
                .Session.varCodDivision = WFGDH.UI.Session.SelUO
                .Session.varCodDepartamento = WFGDH.UI.Session.SelUO
End With


And replace these:

WFGDH.UI.Session.varCodVicepresidencia = Nothing
WFGDH.UI.Session.varCodGCentral = Nothing
WFGDH.UI.Session.varCodDivision = Nothing
WFGDH.UI.Session.varCodDepartamento = Nothing

With these:

With WFGDH.UI.Session
   .varCodVicepresidencia = Nothing
   .varCodGCentral = Nothing
   .varCodDivision = Nothing
   .varCodDepartamento = Nothing
End With
0
 
LVL 13

Expert Comment

by:Rick
Comment Utility
But that will in no way "optimize" the existing code.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:enrique_aeo
Comment Utility
reduce the number of lines of code
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
Untested, but I believe you could do something along these lines (as rick_gwu indicated):
With WFGDH.UI.Session
    Dim option As String
    
    If .desicionSolicitud <> "NO" Then
        .varCodVicepresidencia = .SelUO
        .varCodGCentral = .SelUO
        .varCodDivision = .SelUO
        .varCodDepartamento = .SelUO
    End If

    Select Case True
        Case .varCodVicepresidencia.Equals(String.Empty), .varCodGCentral.Equals(String.Empty), _
             .varCodDivision.Equals(String.Empty), .varCodDepartamento.Equals(String.Empty)
            option = "NN"
        Case .varCodVicepresidencia.Equals(.varCodDepartamento)
            option = "Vp"
        Case.varCodGCentral.Equals(.varCodDepartamento)
            option = "Ce"
        Case .varCodDivision.Equals(.varCodDepartamento)
            option = "Dv"
        Case Else
            option = "Dp"
    End Select
    
    btnNuevoColaborador.Attributes.Add("onclick", String.Format("javascript:return pCargarModal('Ascenso','N','-1','{0}');", option))
    
    If .desicionSolicitud = "NO" Then
        .varCodVicepresidencia = Nothing
        .varCodGCentral = Nothing
        .varCodDivision = Nothing
        .varCodDepartamento = Nothing
    End If
End With

Open in new window

0
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
More of a horizontal savings rather than a vertical one  ; )
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

6 Experts available now in Live!

Get 1:1 Help Now