by AG (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 20th February 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Simple ProperCases Names McDonald and O'Conel
Dim strValue As String
Dim iWords As Integer
If CStr(Value) <> "" Then
Value = Split(Value, " ")
If IsArray(Value) = True Then
Do Until UBound(Value, 1) + 1 = iWords
strValue = strValue & NameProperCaseConvert(Value(iWords)) & " "
iWords = iWords + 1
Loop
strValue = Trim(strValue)
Else
strValue = NameProperCaseConvert(CStr(Value))
End If
NameProperCase = strValue
Else
NameProperCase = ""
End If
End Function
Function NameProperCaseConvert(ByVal Value As String) As String
Dim intRetValue As Integer
Dim strValue As String
strValue = UCase(Left(Value, 1)) & LCase(Mid(Value, 2))
'Checks if name is O'Brain or O'Shear
intRetValue = InStr(1, Value, "'")
If intRetValue >= 1 Then
strValue = UCase(Left(Value, 1)) & Mid(Value, intRetValue, 1) & UCase(Mid(Value, intRetValue + 1, 1)) & LCase(Mid(Value, intRetValue + 2))
End If
intRetValue = InStr(1, Value, "Mc", 1) ' vbTextCompare
If intRetValue >= 1 Then
strValue = UCase(Left(Value, 1)) & LCase(Mid(Value, 2, 1)) & UCase(Mid(Value, intRetValue + 2, 1)) & LCase(Mid(Value, intRetValue + 3))
End If
'intRetValue = InStr(1, Value, "Mac", 1) ' vbTextCompare
'If intRetValue >= 1 Then
' strValue = UCase(Left(Value, 1)) & LCase(Mid(Value, 2, 2)) & UCase(Mid(Value, intRetValue + 3, 1)) & LCase(Mid(Value, intRetValue + 4))
'End If
NameProperCaseConvert = strValue
End Function