Solved

how I can optimize this code? if else

Posted on 2011-03-23
6
433 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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