Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# how I can optimize this code? if else

Posted on 2011-03-23
Medium Priority
440 Views
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
ElseIf (WFGDH.UI.Session.varCodVicepresidencia.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
ElseIf (WFGDH.UI.Session.varCodGCentral.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
ElseIf (WFGDH.UI.Session.varCodDivision.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
Else
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
ElseIf (WFGDH.UI.Session.varCodVicepresidencia.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
ElseIf (WFGDH.UI.Session.varCodGCentral.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
ElseIf (WFGDH.UI.Session.varCodDivision.Equals(WFGDH.UI.Session.varCodDepartamento)) Then
Else
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
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
• 3
• 2

LVL 75

Expert Comment

ID: 35200026
>>  how I can optimize this code

Define "optimize".
0

LVL 13

Accepted Solution

Rick earned 1000 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

ID: 35200046
But that will in no way "optimize" the existing code.
0

Author Comment

ID: 35200196
reduce the number of lines of code
0

LVL 75

Expert Comment

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

If .desicionSolicitud = "NO" Then
.varCodVicepresidencia = Nothing
.varCodGCentral = Nothing
.varCodDivision = Nothing
.varCodDepartamento = Nothing
End If
End With
``````
0

LVL 75

Expert Comment

ID: 35201169
More of a horizontal savings rather than a vertical one  ; )
0

## Featured Post

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
###### Suggested Courses
Course of the Month5 days, 20 hours left to enroll