|
-
Nov 15th, 2011, 02:56 PM
#1
Thread Starter
New Member
VB Code for sentence cap
I'm trying to create a program that allows the user to type multiple sentences and after he clicks the button the program will capatilize the first letter of each sentence. I have done this but the sentences must have a double space after the period to work. I want the program to work even if the user only uses a single space after the period. Here is the code I have so far.
Dim strString As String
Dim searchStrTxt As Integer
Dim strCmpare As String
Dim strRplc As String
Dim strModified As String
Dim strFirstChr As String
strString = TextBox1.Text
strModified = strString
strFirstChr = UCase(Mid$(strModified, 1, 1))
strModified = strFirstChr & Mid$(strModified, 2)
'Search for single-spaced punctuation
For searchStrTxt = 1 To Len(strString) - 1
'DoEvents
strCmpare = Mid$(strModified, searchStrTxt, 3)
If strCmpare = ". " Then
strRplc = Mid$(strString, searchStrTxt, 4)
strModified = Replace$(strModified, strRplc, UCase$(strRplc))
End If
If strCmpare = "? " Then
strRplc = Mid$(strString, searchStrTxt, 4)
strModified = Replace$(strModified, strRplc, UCase$(strRplc))
End If
If strCmpare = "! " Then
strRplc = Mid$(strString, searchStrTxt, 4)
strModified = Replace$(strModified, strRplc, UCase$(strRplc))
End If
Next searchStrTxt
'Assign new string
TextBox1.Text = strModified
Tags for this Thread
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
|