|
-
Jul 7th, 2004, 04:12 PM
#1
Thread Starter
Hyperactive Member
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
-
Jul 7th, 2004, 04:27 PM
#2
Member
Don't think too complicated, the other function 'needed' try/catch, this one doesn't.
VB Code:
Function FN(wholename as string) as String
Dim index As Integer
index = wholename.IndexOf(" ")
If index = -1 Then
FN = wholename
else
FN = wholename.Substring(0, index)
end if
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.
-
Jul 7th, 2004, 05:27 PM
#3
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|