T
TimH
I have the code for parse name(giving credit to original coder) and as I
study the code I get an error that FirstName is zero length even though it is
fully entered such as LastName, FirsName
If there is a middle name the error does not show up
Here is the code for the parse name :
Function ParseName(strOutSal As String, strOutFirst As String, _
strOutMiddle As String, strOutFinal As String, _
strOutSuffix As String, ByVal strInName As Variant) As
Integer
'
' Purpose: Parse a full name into its constituent parts
' Arguments: strOutSal Salutation Output
' strOutFirst First name Output
' strOutMiddle Middle name Output
' strOutFinal Last name Output
' strOutSuffix Suffix Output
' strInName Name to parse
' Returns: Hex flag value, determining which components were filled in
' Author: David Sussman
' Date: 8 June 1997
Dim strTemp() As String ' Temporary work string
Dim intCount As Integer ' No. of elements in above string
Dim intSpacePos As Integer ' Position in string of space
Dim intLoop As Integer ' Loop index
Dim intParsename As Integer ' Return value
Dim intMainCount As Integer ' No. of elements - prefix & suffix
ParseName = 0
ReDim strTemp(0) As String
' exit if name is blank, or add trailing space
' to ensure the InStr does not fail
If IsBlank(strInName) Then Exit Function
strInName = Trim$(strInName) & " "
' break the string into an array
intSpacePos = InStr(strInName, " ")
Do Until intSpacePos = 0
ReDim Preserve strTemp(UBound(strTemp) + 1)
strTemp(UBound(strTemp)) = Trim$(Left$(strInName, intSpacePos - 1))
strInName = LTrim$(Right$(strInName, Len(strInName) - intSpacePos))
intSpacePos = InStr(strInName, " ")
Loop
intCount = UBound(strTemp)
intMainCount = intCount
' is there a prefix
If InStr(csPREFIX_LIST, "." & UCase$(strTemp(1)) & ".") Then
intParsename = intParsename Or csNAME_SAL
strOutSal = strTemp(1)
intMainCount = intMainCount - 1
End If
' is there a suffix
If InStr(csSUFFIX_LIST, "." & UCase$(strTemp(intCount)) & ".") Then
intParsename = intParsename Or csNAME_SUFFIX
strOutSuffix = strTemp(intCount)
intMainCount = intMainCount - 1
End If
' How many elements are left
Select Case intMainCount
Case 0
Case 1
' one element left - must be the surname
If (intParsename And csNAME_SAL) Then
strOutFinal = strTemp(2)
Else
strOutFinal = strTemp(1)
End If
intParsename = intParsename Or csNAME_LAST
Case 2
' two elements left - first surname and name
If (intParsename And csNAME_SUFFIX) Then
strOutFinal = strTemp(intCount - 1)
Else
strOutFinal = strTemp(intCount)
End If
intParsename = intParsename Or csNAME_LAST
If (intParsename And csNAME_SAL) Then
strOutFirst = strTemp(2)
Else
strOutFirst = strTemp(1)
End If
intParsename = intParsename Or csNAME_FIRST
Case Else
' three or more elements - first name, surname
' and one or more middle names
If (intParsename And csNAME_SAL) Then
strOutFirst = strTemp(2)
Else
strOutFirst = strTemp(1)
End If
intParsename = intParsename Or csNAME_LAST
If (intParsename And csNAME_SUFFIX) Then
strOutFinal = strTemp(intCount - 1)
Else
strOutFinal = strTemp(intCount)
End If
intParsename = intParsename Or csNAME_FIRST
' middle names
For intLoop = 2 To intMainCount - 1
If (intParsename And csNAME_SAL) Then
strOutMiddle = Trim$(strOutMiddle) & " " & strTemp(intLoop +
1)
Else
strOutMiddle = Trim$(strOutMiddle) & " " & strTemp(intLoop)
End If
intParsename = intParsename Or csNAME_MID
Next
strOutMiddle = Trim$(strOutMiddle)
End Select
ParseName = intParsename
End Function
study the code I get an error that FirstName is zero length even though it is
fully entered such as LastName, FirsName
If there is a middle name the error does not show up
Here is the code for the parse name :
Function ParseName(strOutSal As String, strOutFirst As String, _
strOutMiddle As String, strOutFinal As String, _
strOutSuffix As String, ByVal strInName As Variant) As
Integer
'
' Purpose: Parse a full name into its constituent parts
' Arguments: strOutSal Salutation Output
' strOutFirst First name Output
' strOutMiddle Middle name Output
' strOutFinal Last name Output
' strOutSuffix Suffix Output
' strInName Name to parse
' Returns: Hex flag value, determining which components were filled in
' Author: David Sussman
' Date: 8 June 1997
Dim strTemp() As String ' Temporary work string
Dim intCount As Integer ' No. of elements in above string
Dim intSpacePos As Integer ' Position in string of space
Dim intLoop As Integer ' Loop index
Dim intParsename As Integer ' Return value
Dim intMainCount As Integer ' No. of elements - prefix & suffix
ParseName = 0
ReDim strTemp(0) As String
' exit if name is blank, or add trailing space
' to ensure the InStr does not fail
If IsBlank(strInName) Then Exit Function
strInName = Trim$(strInName) & " "
' break the string into an array
intSpacePos = InStr(strInName, " ")
Do Until intSpacePos = 0
ReDim Preserve strTemp(UBound(strTemp) + 1)
strTemp(UBound(strTemp)) = Trim$(Left$(strInName, intSpacePos - 1))
strInName = LTrim$(Right$(strInName, Len(strInName) - intSpacePos))
intSpacePos = InStr(strInName, " ")
Loop
intCount = UBound(strTemp)
intMainCount = intCount
' is there a prefix
If InStr(csPREFIX_LIST, "." & UCase$(strTemp(1)) & ".") Then
intParsename = intParsename Or csNAME_SAL
strOutSal = strTemp(1)
intMainCount = intMainCount - 1
End If
' is there a suffix
If InStr(csSUFFIX_LIST, "." & UCase$(strTemp(intCount)) & ".") Then
intParsename = intParsename Or csNAME_SUFFIX
strOutSuffix = strTemp(intCount)
intMainCount = intMainCount - 1
End If
' How many elements are left
Select Case intMainCount
Case 0
Case 1
' one element left - must be the surname
If (intParsename And csNAME_SAL) Then
strOutFinal = strTemp(2)
Else
strOutFinal = strTemp(1)
End If
intParsename = intParsename Or csNAME_LAST
Case 2
' two elements left - first surname and name
If (intParsename And csNAME_SUFFIX) Then
strOutFinal = strTemp(intCount - 1)
Else
strOutFinal = strTemp(intCount)
End If
intParsename = intParsename Or csNAME_LAST
If (intParsename And csNAME_SAL) Then
strOutFirst = strTemp(2)
Else
strOutFirst = strTemp(1)
End If
intParsename = intParsename Or csNAME_FIRST
Case Else
' three or more elements - first name, surname
' and one or more middle names
If (intParsename And csNAME_SAL) Then
strOutFirst = strTemp(2)
Else
strOutFirst = strTemp(1)
End If
intParsename = intParsename Or csNAME_LAST
If (intParsename And csNAME_SUFFIX) Then
strOutFinal = strTemp(intCount - 1)
Else
strOutFinal = strTemp(intCount)
End If
intParsename = intParsename Or csNAME_FIRST
' middle names
For intLoop = 2 To intMainCount - 1
If (intParsename And csNAME_SAL) Then
strOutMiddle = Trim$(strOutMiddle) & " " & strTemp(intLoop +
1)
Else
strOutMiddle = Trim$(strOutMiddle) & " " & strTemp(intLoop)
End If
intParsename = intParsename Or csNAME_MID
Next
strOutMiddle = Trim$(strOutMiddle)
End Select
ParseName = intParsename
End Function