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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

nepaluzCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
nffvrxqgrcfqvvcCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.