|
-
Apr 23rd, 2007, 02:55 AM
#1
Thread Starter
Lively Member
UCase first character of every Sentence in textbox
Hi,
can any one help me about converting the first character in uppercase in a sentence
Thnks
-
Apr 23rd, 2007, 02:58 AM
#2
Lively Member
Re: UCase first character of every Sentence in textbox
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
-
Apr 23rd, 2007, 02:58 AM
#3
Fanatic Member
Re: UCase first character of every Sentence in textbox
vb Code:
msgbox StrConv("test test test",vbProperCase)
-
Apr 23rd, 2007, 02:58 AM
#4
Re: UCase first character of every Sentence in textbox
Use the format command with the vbProperCase argument.
Using Mid$ to find the beginning of a sentence allow you to format the first word.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Apr 23rd, 2007, 04:14 AM
#5
Thread Starter
Lively Member
Re: UCase first character of every Sentence in textbox
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
-
Apr 23rd, 2007, 08:31 AM
#6
Re: UCase first character of every Sentence in textbox
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
-
Apr 23rd, 2007, 05:28 PM
#7
Re: UCase first character of every Sentence in textbox
 Originally Posted by Ellis Dee
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.
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
|