|
-
Nov 7th, 2000, 10:10 AM
#1
Thread Starter
Hyperactive Member
Everytime someone types something into a text box I want the first letter of every word to be a capitol....for example turn every letter capitol after every space.
so in the keypress event
if someone typed
john carl
it would change it to John Carl
-------------------------------
How would i go about doing that?
-RaY
VB .Net 2010 (Ultimate)
-
Nov 7th, 2000, 10:13 AM
#2
Hyperactive Member
In the change event, make a cycle finding spaces and convert the string.
-
Nov 7th, 2000, 10:35 AM
#3
Lively Member
Here it is......
Hi,
Here is the code for your query...
Private Sub Text1_Change()
Text1.SelStart = Len(Text1) + 1
Text1 = StrConv(Text1.Text, vbProperCase)
End Sub
This will convert the first letter of each string to uppercase as john smith to John Smith.
Cheers!!!
-
Nov 7th, 2000, 10:46 AM
#4
Fanatic Member
This would not capitalise the first letter so you need something like
Code:
If Left$(MyStr, 1) <> " " Then MyStr = UCase$(Left$(MyStr, 1)) & Right$(MyStr, Len(MyStr) - 1)
i = 1
Do While InStr(i, MyStr, " ")
MyChars = Mid$(MyStr, InStr(i, MyStr, " "), 2)
i = InStr(i, MyStr, " ") + 1 ' Go past space...
RepChars = UCase$(MyChars)
MyStr = Replace(MyStr, MyChars, RepChars)
Loop
NB This is highly inefficient, but it is off the top of my head. Might give you a starting point though.
Cheers,
Paul.
Not nearly so tired now...
Haven't been around much so be gentle...
-
Nov 7th, 2000, 10:46 AM
#5
Thread Starter
Hyperactive Member
One problem
I got vb3, doesnt support that.
-RaY
VB .Net 2010 (Ultimate)
-
Nov 7th, 2000, 01:27 PM
#6
Hyperactive Member
Hmm. Try adding this to text1_change. I never had anything below vb4 so don't know what you can't do?
Code:
If Len(Text1.Text) = 1 Then
Text1.Text = UCase$(Text1.Text)
Else
If Mid$(Text1.Text, Len(Text1.Text) - 1, 1) = " " Then
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) _
& UCase$(Right(Text1.Text, 1))
End If
End If
Text1.SelStart = Len(Text1.Text)
-
Nov 7th, 2000, 01:29 PM
#7
Hyperactive Member
Oops
Sorry. Add this to the top of the code :
Code:
If Len(Text1.Text) = 0 Then Exit Sub
I hate it when I find bugs!
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
|