Return value from Function

I am calling a function to return the value with some clauses however the value is not being returned correctly do advise if there is any flaw in the code attached.

The value is being updated as null did I miss anything in the code??

I appreciate if somebody can advise me on this..Thanks!!
currentColumn = "BORR1CITIZENRESTYPE"
            Row.BORR1CITIZENRESTYPE = DetermineCitizenResType(Row.BORR1CITIZEN, Row.BORR1ALIEN, Row.BORR1CITIZENRESTYPENT, Row.SourceSystem)


 Private Function DetermineCitizenResType(ByVal citizen As String, ByVal alien As String, ByVal originalValue As String, ByVal systemName As String) As String

        If systemName = NetOSystemName Then
            If String.IsNullOrEmpty(citizen) = False AndAlso String.Compare(citizen, "Y", True) = 0 Then
                Return "USCitizen"
            ElseIf String.IsNullOrEmpty(alien) = False AndAlso String.Compare(alien, "Y", True) = 0 Then
                Return "PermanentResidentAlien"
            Else
                Return "NonPermanentResidentAlien"
            End If
        End If

        
        If systemName = OmniSystemName Then
            If String.IsNullOrEmpty(originalValue) = True Then
                Return String.Empty
            Else
                Return originalValue
            End If
        End If
    End Function

Open in new window

onebite2Asked:
Who is Participating?
 
nepaluzConnect With a Mentor Commented:
try
If Not String.IsNullOrEmpty(citizen) Then
   Return If(citizen = "Y", "USCitizen", "NonPermanentResidentAlien")
ElseIf Not String.IsNullOrEmpty(alien)
   Return If(alien = "Y", "PermanentResidentAlien", "NonPermanentResidentAlien"
Else
   Return "NonPermanentResidentAlien"
End If

Open in new window

etc ....
0
 
HugoHiaslCommented:
Replace

Return "YourValue"

by

DetermineCitizenResType = "YourValue"



0
 
HugoHiaslCommented:
The notation I wrote in the last post is a carry over from vb.

Your code looks also fine. You should step into the code and check if your code uses one of the if parts.

To debug this you could also try to add else-parts to the main if clauses returning a debug value.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
onebite2Author Commented:
@Hugo Hiasl

I cannot debug into the code because it runs as a script inside a SSIS package  through an interface and does not stop with break points ..so not sure how to fix this...can u suggest me any other way??
0
 
nffvrxqgrcfqvvcCommented:
It would indicate that there is occurrences when you run your function that it doesn't make it into any of your If block conditions. This means the return value is defaulting to NULL because the very last line doesn't return anything if your function never gets into the if statements.
Private Function DetermineCitizenResType(ByVal citizen As String, ByVal alien As String, ByVal originalValue As String, ByVal systemName As String) As String

        If systemName = NetOSystemName Then
            If String.IsNullOrEmpty(citizen) = False AndAlso String.Compare(citizen, "Y", True) = 0 Then
                Return "USCitizen"
            ElseIf String.IsNullOrEmpty(alien) = False AndAlso String.Compare(alien, "Y", True) = 0 Then
                Return "PermanentResidentAlien"
            Else
                Return "NonPermanentResidentAlien"
            End If
        End If

        
        If systemName = OmniSystemName Then
            If String.IsNullOrEmpty(originalValue) = True Then
                Return String.Empty
            Else
                Return originalValue
            End If
        End If
'
' Your function did not make it into any if block condition. The string is NULL
Return "I did not enter any If block condition!"
    End Function

Open in new window

0
 
nffvrxqgrcfqvvcConnect With a Mentor Commented:
You may also want to verify that the strings your comparing are equal remember a string doesn't match if you don't take care of case sensitivity. You could use .ToLower() .ToUpper() or String.Equals()
If String.Equals(systemName, NetOSystemName, StringComparison.CurrentCultureIgnoreCase) Then
End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.