Results 1 to 3 of 3

Thread: Another name function...help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Location
    Utah, USA
    Posts
    353

    Another name function...help!

    This is the data I can have:

    Gomez Maria F
    Gomez Maria
    Gomez

    When I just have the last name and nothing else, it gives me an error. How can I fix this?

    Here is the function:

    Function FirstName(ByVal WholeName As String) As String
    Dim arr() As String
    Dim FName As String

    WholeName = Replace(WholeName, ",", " ")
    arr = Split(WholeName, " ")

    If arr(1) = "III" Or arr(1) = "JR" Or arr(1) = "SR" Or arr(1) = "II" Then
    Try
    FName = arr(2)
    Catch ex As Exception
    FName = ""
    End Try
    Else
    Try
    FName = arr(1)
    Catch ex As Exception
    FName = ""
    End Try
    End If
    Return FName

    End Function

  2. #2
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    Don't think too complicated, the other function 'needed' try/catch, this one doesn't.

    VB Code:
    1. Function FN(wholename as string) as String
    2.         Dim index As Integer
    3.  
    4.         index = wholename.IndexOf(" ")
    5.         If index = -1 Then
    6.             FN = wholename
    7.         else
    8.            FN = wholename.Substring(0, index)
    9.         end if
    10. End Function

    Just call FN and LN (the other function already posted) whenever you need them.
    Last edited by cphoenixc; Jul 7th, 2004 at 04:42 PM.

  3. #3
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    The problem is coming because if you only have a last name, all you have is arr(0). You can't refer to arr(1) or above in that case.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width