VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will convert the first letter of each word following the spacebar being pressed to UPPERC

by Eric Morrison (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Wed 29th November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code will convert the first letter of each word following the spacebar being pressed to UPPERCASE. Great for a text field for an address

API Declarations


' Eric Morrison '
' November 29/00 '
' [email protected] '
' Uppercase code '

Dim KP As Boolean
Dim SB As String
Dim strResult As String

Rate This code will convert the first letter of each word following the spacebar being pressed to UPPERC



' 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 = 32 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
    KP = False
End If
End Sub


Download this snippet    Add to My Saved Code

This code will convert the first letter of each word following the spacebar being pressed to UPPERC Comments

No comments have been posted about This code will convert the first letter of each word following the spacebar being pressed to UPPERC. Why not be the first to post a comment about This code will convert the first letter of each word following the spacebar being pressed to UPPERC.

Post your comment

Subject:
Message:
0/1000 characters