Solved

how I can optimize this code? if else

Posted on 2011-03-23
6
427 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
[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
  • 3
  • 2
6 Comments
 
LVL 75

Expert Comment

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

Define "optimize".
0
 
LVL 13

Accepted Solution

by:
Rick earned 250 total points
ID: 35200037
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
ID: 35200046
But that will in no way "optimize" the existing code.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:enrique_aeo
ID: 35200196
reduce the number of lines of code
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35201137
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 75

Expert Comment

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

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 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