Results 1 to 7 of 7

Thread: UCase first character of every Sentence in textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    127

    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

  2. #2
    Lively Member chxxangie's Avatar
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    79

    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

  3. #3
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Re: UCase first character of every Sentence in textbox

    vb Code:
    1. msgbox StrConv("test test test",vbProperCase)

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    127

    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

  6. #6
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    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

  7. #7
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: UCase first character of every Sentence in textbox

    Quote 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
  •  



Click Here to Expand Forum to Full Width