?
Solved

recursive method

Posted on 2011-05-05
11
Medium Priority
?
354 Views
Last Modified: 2012-05-11
Hi experts, I have this method that is recursive ObtenerUsuarioEstacion. Sometimes this method completes its execution and when I check in the database I see with surprise that estacion,  codigoUsuario and username are empty, that modification I make ends its execution usuarioEstacion have provided data

Public Sub ObtenerUsuarioEstacion(ByVal strNumeroUltimus As String)
.
.
.
Dim usuarioEstacion As String = objLogicBandeja.fArrObtenerUsuarioEstacionDestino(Constantes.ProcesoIncrementoPlanta, intEstadoIncidentesUlt, WFGDHUtilitario.ObtieneKeyWebConfig("wsUltimusWBC"), strNumeroUltimus.Replace("IP-", ""))

        If String.IsNullOrEmpty(usuarioEstacion) Then
            ObtenerUsuarioEstacion(strNumeroUltimus)
        Else
            arrDatosDestino = usuarioEstacion.Split("-")
            estacion = arrDatosDestino(0).ToString
            codigoUsuario = arrDatosDestino(1).ToString
            nombreUsuario = arrDatosDestino(2).ToString
        End If

        Dim oLIncrementoPlanta As New LIncrementoPlanta
        oLIncrementoPlanta.ActualizarUserEstacion(Solicitud.intIdNumeroProvision, estacion, codigoUsuario, nombreUsuario)

End Sub
0
Comment
Question by:enrique_aeo
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 31

Accepted Solution

by:
MlandaT earned 668 total points
ID: 35702103
How about moving the call to oLIncrementoPlanta.ActualizarUserEstacion into the IF as well? Like so:
Public Sub ObtenerUsuarioEstacion(ByVal strNumeroUltimus As String)
.
.
.
Dim usuarioEstacion As String = objLogicBandeja.fArrObtenerUsuarioEstacionDestino(Constantes.ProcesoIncrementoPlanta, intEstadoIncidentesUlt, WFGDHUtilitario.ObtieneKeyWebConfig("wsUltimusWBC"), strNumeroUltimus.Replace("IP-", ""))

        If String.IsNullOrEmpty(usuarioEstacion) Then

            ObtenerUsuarioEstacion(strNumeroUltimus)

        Else

            arrDatosDestino = usuarioEstacion.Split("-")
            estacion = arrDatosDestino(0).ToString
            codigoUsuario = arrDatosDestino(1).ToString
            nombreUsuario = arrDatosDestino(2).ToString

            Dim oLIncrementoPlanta As New LIncrementoPlanta
            oLIncrementoPlanta.ActualizarUserEstacion(Solicitud.intIdNumeroProvision, estacion, codigoUsuario, nombreUsuario)

        End If

End Sub

Open in new window

0
 
LVL 61

Expert Comment

by:HainKurt
ID: 35702161
this is wrong


Public Sub ObtenerUsuarioEstacion(ByVal strNumeroUltimus As String)
  Dim usuarioEstacion As String = ...
  If String.IsNullOrEmpty(usuarioEstacion) Then
    ObtenerUsuarioEstacion(strNumeroUltimus)
  Else ...

if initially or some point strNumeroUltimus is null it goes into infinite loop...
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 35702191
actually what I mean is, at a point or initially, for a value of strNumeroUltimus, usuarioEstacion is calculated as null. Then here you are calling the function with same value of strNumeroUltimus which will repeat the logic and you will end up an infinite loop...
0
Technology Partners: 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: 35702196
HainKurt and how to correct it?
0
 
LVL 31

Expert Comment

by:MlandaT
ID: 35702280
I think the problem is related to the fact that in the way the author has structured their code, the call to
oLIncrementoPlanta.ActualizarUserEstacion(Solicitud.intIdNumeroProvision, estacion, codigoUsuario, nombreUsuario)

Open in new window

gets executed even when the values are null, thus resulting in blank values showing in the database.
0
 
LVL 61

Assisted Solution

by:HainKurt
HainKurt earned 664 total points
ID: 35702394
HainKurt and how to correct it?

dont know what the logic is here :)

maybe this
Public Sub ObtenerUsuarioEstacion(ByVal strNumeroUltimus As String)
  if String.IsNullOrEmpty(strNumeroUltimus) Then exit sub
  Dim usuarioEstacion As String = objLogicBandeja.fArrObtenerUsuarioEstacionDestino(Constantes.ProcesoIncrementoPlanta, intEstadoIncidentesUlt, WFGDHUtilitario.ObtieneKeyWebConfig("wsUltimusWBC"), strNumeroUltimus.Replace("IP-", ""))
  if String.IsNullOrEmpty(usuarioEstacion) Then exit sub

    arrDatosDestino = usuarioEstacion.Split("-")
    estacion = arrDatosDestino(0).ToString
    codigoUsuario = arrDatosDestino(1).ToString
    nombreUsuario = arrDatosDestino(2).ToString
    ObtenerUsuarioEstacion(nombreUsuario)

  Dim oLIncrementoPlanta As New LIncrementoPlanta
  oLIncrementoPlanta.ActualizarUserEstacion(Solicitud.intIdNumeroProvision, estacion, codigoUsuario, nombreUsuario)
End Sub

Open in new window

0
 
LVL 61

Expert Comment

by:HainKurt
ID: 35702420
or this
Public Sub ObtenerUsuarioEstacion(ByVal strNumeroUltimus As String)
  if String.IsNullOrEmpty(strNumeroUltimus) Then exit sub
  Dim usuarioEstacion As String = objLogicBandeja.fArrObtenerUsuarioEstacionDestino(Constantes.ProcesoIncrementoPlanta, intEstadoIncidentesUlt, WFGDHUtilitario.ObtieneKeyWebConfig("wsUltimusWBC"), strNumeroUltimus.Replace("IP-", ""))
  if String.IsNullOrEmpty(usuarioEstacion) Then exit sub

  arrDatosDestino = usuarioEstacion.Split("-")
  estacion = arrDatosDestino(0).ToString
  codigoUsuario = arrDatosDestino(1).ToString
  nombreUsuario = arrDatosDestino(2).ToString

  if String.IsNullOrEmpty(nombreUsuario) Then exit sub

  Dim oLIncrementoPlanta As New LIncrementoPlanta
  oLIncrementoPlanta.ActualizarUserEstacion(Solicitud.intIdNumeroProvision, estacion, codigoUsuario, nombreUsuario)
  ObtenerUsuarioEstacion(nombreUsuario)
End Sub

Open in new window

0
 
LVL 5

Assisted Solution

by:dexion432
dexion432 earned 668 total points
ID: 35704267
your code writes to the db when usuarioEstacion is "  " for example. call Trim on usuarioEstacion before "  If String.IsNullOrEmpty(usuarioEstacion) Then"
0
 

Author Comment

by:enrique_aeo
ID: 35707787
something like this
    Public Sub ActualizarUsuarioEstacion(ByVal strNumeroUltimus As String)
       
        If String.IsNullOrEmpty(strNumeroUltimus) Then Exit Sub
        ObtenerUsuarioEstacion(strNumeroUltimus)

    End Sub

    Public Sub ObtenerUsuarioEstacion(ByVal strNumeroUltimus As String)
        Dim objLogicBandeja As New LUltimus
        Dim intEstadoIncidentesUlt As Integer = 0
        Dim intNumeroProvicion As Integer = 0
        Dim estacion As String = ""
        Dim codigoUsuario As String = ""
        Dim nombreUsuario As String = ""
        Dim arrDatosDestino As String() = Nothing

        intEstadoIncidentesUlt = EConstante.eFilter.nFilter_Current
        Dim usuarioEstacion As String = objLogicBandeja.fArrObtenerUsuarioEstacionDestino(Constantes.ProcesoIncrementoPlanta, intEstadoIncidentesUlt, WFGDHUtilitario.ObtieneKeyWebConfig("wsUltimusWBC"), strNumeroUltimus.Replace("IP-", ""))

        usuarioEstacion = usuarioEstacion.Trim()
        If String.IsNullOrEmpty(usuarioEstacion) Then
            ObtenerUsuarioEstacion(strNumeroUltimus)
        Else
            arrDatosDestino = usuarioEstacion.Split("-")
            estacion = arrDatosDestino(0).ToString
            codigoUsuario = arrDatosDestino(1).ToString
            nombreUsuario = arrDatosDestino(2).ToString

            Dim oLIncrementoPlanta As New LIncrementoPlanta
            oLIncrementoPlanta.ActualizarUserEstacion(Solicitud.intIdNumeroProvision, estacion, codigoUsuario, nombreUsuario)
        End If
0
 

Author Comment

by:enrique_aeo
ID: 35709020
when usuarioestacion = nothing as a control for the recursive call does not fail
usuarioESTACION.jpg
0
 

Author Comment

by:enrique_aeo
ID: 35713326
hi dexion432:
 if I put usuarioEstacion.Trim () and usuarioEstacion is nothing I get an error
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

612 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