Hi,
can any one help me about converting the first character in uppercase in a sentence
Thnks
Printable View
Hi,
can any one help me about converting the first character in uppercase in a sentence
Thnks
Code:Private Sub Command1_Click()
Text1.Text = ""
Text1.SetFocus
End Sub
Private Sub Text1_Change()
Dim s As Integer
s = Text1.SelStart
Text1.Text = StrConv(Text1.Text, vbProperCase)
Text1.SelStart = s
End Sub
vb Code:
msgbox StrConv("test test test",vbProperCase)
Use the format command with the vbProperCase argument.
Using Mid$ to find the beginning of a sentence allow you to format the first word.
Dim s As Integer
s = Text1.SelStart
Text1.Text = StrConv(Text1.Text, vbProperCase)
Text1.SelStart = s
It converts 1st character of every word to uppercase, instead i wants to convert first character of the sentence.
Thanks
This isn't super-optimized, but it should work.Code:Public Function SentenceCase(pstrText As String) As String
Dim i As Long
Dim bytArray() As Byte
Dim blnUpper As Boolean
blnUpper = True
bytArray = StrConv(pstrText, vbFromUnicode)
For i = 0 To UBound(bytArray)
Select Case bytArray(i)
Case 33, 46, 63 ' exclamation point, period or question mark
blnUpper = True
Case 65 To 90, 97 To 122
If blnUpper Then
bytArray(i) = Asc(UCase$(Chr$(bytArray(i))))
blnUpper = False
End If
End Select
Next
SentenceCase = StrConv(bytArray, vbUnicode)
Erase bytArray
End Function
Looks pretty good to me.:thumb:Quote:
Originally Posted by Ellis Dee