VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This will catch a non-capitalized word after punctuation and a space (new sentence) and auto-capita

by Chris Mauck (2 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sun 25th February 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This will catch a non-capitalized word after punctuation and a space (new sentence) and auto-capitalize it. Useful for catching a simple

Rate This will catch a non-capitalized word after punctuation and a space (new sentence) and auto-capita



Dim KP As Boolean
Dim PD As Boolean
Dim SB As String
Dim strResult As String
Dim strTemp As String
' On the form place a textbox named Text1 '
' And now just place the following code and '
' Wala, test it out. '

Private Sub Form_Load()
    ' Clear the textbox field
    Text1 = ""
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
On Error Resume Next
    
If Len(Text1) = 1 Then
    strResult = Text1
    ' Set first letter on left of string to uppercase
    strResult = UCase$(Left$(strResult, 1)) & Mid$(strResult, 2)
    ' Place results of uppercase statement in txtField
    Text1 = strResult
     ' Place cursor at end of txt string
     Text1.SelStart = Len(strResult) + 1
 ' Check to see if Spacebar was pressed, Y=Yes
 ElseIf SB = "Y" Then
     ' strTemp is the 1st letter after the spacebar is pressed & set to uppercase
     strTemp = UCase$(Right$(Text1, 1))
     ' txtField becomes strresult + the uppercase strTemp
     Text1 = strResult & strTemp
    ' Place the cursor at the end of the string
    Text1.SelStart = Len(strResult) + 1
    ' Set SB to NULL
    SB = ""
End If
strResult = Text1

If KeyAscii = 46 Then
    PD = True
 ElseIf KeyAscii = 33 Then
    PD = True
 ElseIf KeyAscii = 63 Then
    PD = True
 ElseIf KeyAscii = 32 And PD = True Then
    ' If the spacebar is pressed then  KP is true
    KP = True
 ' Spacebar was pressed on previous key
 ElseIf KP = True Then
     ' Set SB to Yes identifying spacebar was pressed
     SB = "Y"
    ' Set KP to False until next time spacebar is pressed
    PD = False
    KP = False
End If
End Sub



Download this snippet    Add to My Saved Code

This will catch a non-capitalized word after punctuation and a space (new sentence) and auto-capita Comments

No comments have been posted about This will catch a non-capitalized word after punctuation and a space (new sentence) and auto-capita. Why not be the first to post a comment about This will catch a non-capitalized word after punctuation and a space (new sentence) and auto-capita.

Post your comment

Subject:
Message:
0/1000 characters