D
Darts via AccessMonster.com
What is the programming code for Title Case.
I want to be abel to type john smith without using shift key.
thanks much
I want to be abel to type john smith without using shift key.
thanks much
Paul said:Hi,
I don't remember where I first saw this but it works well.
Public Function LowerToProperCase(ByVal edit$) As String
' The LowerToProperCase function looks through the string
' seeing which characters are letters and which are not.
' It capitalizes those that satisfy the rules shown in the
' comment at the beginning of the function.
' Subroutine to normalize 1 piece of data to Capitalize.
' Inputs: char label.
' Outputs: Normalized Label.
' Does more than I need here, will leave it as is.
' Rules Cap char after ['][>][-][.][/][#][0-9][&][Mc][Mac][,][(],[\],[|]
' Cap char after [!][@][$][%][^][*][+][=]["]['(not s)]
' abbreviations [po][nw][ne][sw][se][ii] are capitalized
' abbreviations [st][th][nd][rd][c/o] are not capitalized
' words [of][and][van][der][de] are not capitalized.
On Error Resume Next
Dim A$, b$, c$, i%
If Len(Trim(edit$)) = 0 Then
LowerToProperCase = edit$
Exit Function
End If
edit$ = edit$ + Space$(3) ' End of word match ???
Mid$(edit$, 1, 1) = UCase$(Mid$(edit$, 1, 1)) ' Cap first char.
If Mid$(edit$, 1, 3) = "Po " Then
Mid$(edit$, 1, 3) = "PO " ' PO Box cap.
End If
b$ = "NwNeSwSeIi" ' NW NE SW SE II.
If Mid$(edit$, 1, 2) = "Mc" Then
Mid$(edit$, 3, 1) = UCase$(Mid$(edit$, 3, 1))
End If
If Mid$(edit$, 1, 3) = "Mac" Then
Mid$(edit$, 4, 1) = UCase$(Mid$(edit$, 3, 1))
End If
If Mid$(edit$, 1, 1) > Chr$(47) And Mid$(edit$, 1, 1) < Chr$(58) Then
Mid$(edit$, 2, 1) = UCase$(Mid$(edit$, 2, 1)) ' Nos 0 - 9.
End If
c$ = " >-./#&,(!@$%^*+=\|" & Chr(34)
If InStr(c$, Mid$(edit$, 1, 1)) > 0 Then
Mid$(edit$, 2, 1) = UCase$(Mid$(edit$, 2, 1))
End If
For i% = 2 To Len(edit$)
If InStr(b$, Mid$(edit$, i%, 2)) > 0 Then
If Mid$(edit$, i% - 1, 1) = " " And Mid$(edit$, i% + 2, 1) = " "
Then
Mid$(edit$, i%, 2) = UCase$(Mid$(edit$, i%, 2))
End If
i% = i% + 2
End If
If Mid$(edit$, i%, 4) = " of " Then ' Don't cap word "of".
i% = i% + 2
GoTo skipcapchar
ElseIf Mid$(edit$, i%, 5) = " and " Then ' Don't cap word "and".
i% = i% + 3
GoTo skipcapchar
' Uncomment any of these lines if you want to keep parts of a name in lower
case eg da Vinci instead of Da Vinci.
' ElseIf Mid$(edit$, i%, 5) = " der " Then ' Don't cap word "der".
' i% = i% + 3
' GoTo skipcapchar
' ElseIf Mid$(edit$, i%, 5) = " van " Then ' Don't cap word "van".
' i% = i% + 3
' GoTo skipcapchar
' ElseIf Mid$(edit$, i%, 4) = " da " Then ' Don't cap word "de".
' i% = i% + 2
' GoTo skipcapchar
' ElseIf Mid$(edit$, i%, 4) = " de " Then ' Don't cap word "de".
' i% = i% + 2
' GoTo skipcapchar
' ElseIf Mid$(edit$, i%, 4) = " di " Then ' Don't cap word "da".
' i% = i% + 2
' GoTo skipcapchar
' ElseIf Mid$(edit$, i%, 4) = " di " Then ' Don't cap word "di".
' i% = i% + 2
' GoTo skipcapchar
ElseIf Mid$(edit$, i%, 5) = " c/o " Then ' Don't cap abbrev c/o.
i% = i% + 3
GoTo skipcapchar
End If
If InStr(c$, Mid$(edit$, i%, 1)) > 0 And i% < Len(edit$) Then
Mid$(edit$, i% + 1, 1) = UCase(Mid$(edit$, i% + 1, 1))
End If
If Mid$(edit$, i%, 1) = Chr$(39) And Mid$(edit$, i% + 1, 1) <> "s"
Then
Mid$(edit$, i% + 1, 1) = UCase$(Mid$(edit$, i% + 1, 1)) ' Catch
"'s".
End If
If Mid$(edit$, i%, 2) = "Mc" Then
Mid$(edit$, i% + 2, 1) = UCase$(Mid$(edit$, i% + 2, 1))
End If
If Mid$(edit$, i%, 3) = "Mac" Then
Mid$(edit$, i% + 3, 1) = UCase$(Mid$(edit$, i% + 3, 1))
End If
If InStr("0123456789", Mid$(edit$, i%, 1)) > 0 Then ' Nos 0-9.
A$ = Mid$(edit$, i% + 1, 2)
If A$ <> "st" And A$ <> "th" And A$ <> "nd" And A$ <> "rd" Then
Mid$(edit$, i% + 1, 1) = UCase$(Mid$(edit$, i% + 1, 1)) '
No's 0-9.
End If
End If
skipcapchar:
Next i%
edit$ = RTrim$(edit$) ' Trim space added earlier.
LowerToProperCase = edit$
End Function
Use example:
strName = LowerToProperCase(strName)
Have fun.
Regards
Paul
Darts via AccessMonster.com said:What is the programming code for Title Case.
I want to be abel to type john smith without using shift key.
thanks much