Results 1 to 7 of 7

Thread: Question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    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)

  2. #2
    Hyperactive Member
    Join Date
    Nov 2000
    Location
    Mexico City
    Posts
    306
    In the change event, make a cycle finding spaces and convert the string.

  3. #3
    Lively Member
    Join Date
    Oct 2000
    Location
    Chicago
    Posts
    97

    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!!!
    Anil

  4. #4
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    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...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    One problem

    I got vb3, doesnt support that.
    -RaY
    VB .Net 2010 (Ultimate)

  6. #6
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    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)

  7. #7
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372

    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
  •  



Click Here to Expand Forum to Full Width