Results 1 to 10 of 10

Thread: Deleting the characters from textbox

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    47
    Hi!

    I'm using VB6 in Win98. How is it possible to remove e.g. seven (7) characters (also spacebar hits are counted) from the beginning part of the textbox's text-property. For example how can I convert "eGtg12 Hello You All" to "Hello You All"?

    And is there any kind of way to change all the first leters of the words in textbox to capitals. Like "a man who walks" -> "A Man Who Walks"?


    RieBBo

  2. #2
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217

    Talking

    Gee, it seems like I'm the only one answering your questions
    tonight, cool! I'm a Guru by default

    Here's the code you asked for:
    Code:
       'To remove a certain number of characters from a string.
       'Note: You must add 1 to the number of characters that you
       'want removed because the Mid function uses a base
       'character position of 1.
       Text1.Text = Mid$(Text1.Text, 8)
    To capitalize all of the first characters of words in a
    string is a little more complicated, use this little
    function that I just wipped up:
    Code:
    Private Function CapitalizeChars( _
            sOrigString As String) As String
       
       Dim bytChars() As Byte
       Dim idx As Integer
       Dim bToCapitalize As Boolean
       
       ReDim bytChars(Len(sOrigString) - 1)
       bytChars = StrConv(sOrigString, vbFromUnicode)
       bToCapitalize = True
       
       For idx = 0 To Len(sOrigString) - 1
          
          If bytChars(idx) < 65 _
          Or bytChars(idx) > 122 _
          Or (bytChars(idx) > 90 _
          And bytChars(idx) < 97) Then
             bToCapitalize = True
          Else
             
             If bToCapitalize = True Then
                bytChars(idx) = Asc(UCase(Chr(bytChars(idx))))
                bToCapitalize = False
             End If
             
          End If
          
       Next idx
       
       CapitalizeChars = StrConv(bytChars, vbUnicode)
    End Function
    Call the function like this:
    Code:
       Text1.Text = CapitalizeChars(Text1.Text)
    Hope that this helps
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  3. #3
    Guest

    Cool Gee what version of vb are you using

    For capitilisation of first letters in a string of words
    have a look at the strconv function, one line of code will resolve your requirement.

    This works for vb5 & vb6

    Sorry only just got to your post, after destroying "I Love You" crap.

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    47
    Okay.....


    And how can I remove the last threee characters from the TextBox.text?

    The long code above which mr. SonGouki nicely posted works fine, but not with scands, like ä and ö and å.....how to make these also work?



    RieBBo

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    To remove last 3 characters:
    Code:
    Text1 = Left(Text1, Len(Text1) - 3)
    Can you be more specific with your second question???

  6. #6
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Hey lkivik,
    I've been busy the past couple of days, here's my original
    code, slightly modified to capitalize scands as well. Enjoy!
    Code:
    Private Function CapitalizeChars( _
            sOrigString As String) As String
       
       Dim bytChars() As Byte
       Dim idx As Integer
       Dim bToCapitalize As Boolean
       
       ReDim bytChars(Len(sOrigString) - 1)
       bytChars = StrConv(sOrigString, vbFromUnicode)
       bToCapitalize = True
       
       For idx = 0 To Len(sOrigString) - 1
          
          Select Case bytChars(idx)
             
             Case 97 To 122, 224 To 255
                
                If bToCapitalize = True Then
                   bytChars(idx) = bytChars(idx) - 32
                   bToCapitalize = False
                End If
                
             Case Else
                bToCapitalize = True
             
          End Select
          
       Next idx
       
       CapitalizeChars = StrConv(bytChars, vbUnicode)
    End Function
    Dan PM
    Analyst Programmer

    VB6 SP3 (also VB4 16-bit sometimes )

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    47
    I tried your new modified code, SonG: Why does it convert always the two first characters to capitals...not just one... eg. BIg REd HOuse



    .. Can it have something to do with if the word's first character is already capitalized ..??

    [Edited by lkivik on 05-10-2000 at 10:27 AM]

  8. #8
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    You can use StrConv function that will convert each first charater to Proper Case:
    Code:
    MsgBox StrConv("this is a small text that will be converted to propert case.", vbProperCase)

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2000
    Posts
    47
    Hey that (strconv-function) works, also with scands !!!
    but still I have one thing in my mind...

    Let's take an example: around_the_corner . How to convert it to Around_The_Corner ? I want to make the function handle "_"-marks like they would be spacebar hits....



  10. #10
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Lightbulb Try this.

    This function will convert the first character of every word into upper case. At the minute if there is a non aplha-numeric number the following letter will be converted to upper case.

    e.g.
    "hello out-there>world" will become
    "Hello Out-There>World"

    I am sure you can change it to suit your needs.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Text2.Text = convertUpper(Text1.Text)
    End Sub
    
    Private Function convertUpper(strInput As String) As String
        Dim i As Long
        Dim blUpper As Boolean
        Dim strChar As String
        
        convertUpper = UCase$(Mid$(strInput, 1, 1))
        
        For i = 2 To Len(strInput)
          strChar = Asc(Mid$(strInput, i, 1))
          If blUpper = True Then
            strChar = Asc(UCase$(Chr(strChar)))
            blUpper = False
          End If
    
          'if the char is not 0 - 9
          If (strChar < 48) Or (strChar > 57) Then
            'if the char is not A - Z
            If (strChar < 65) Or (strChar > 90) Then
              'if the char is not a - z
              If (strChar < 97) Or (strChar > 122) Then
                blUpper = True
              End If
            End If
          End If
    
          convertUpper = convertUpper & Chr(strChar)
        Next i
    
    End Function
    Iain, thats with an i by the way!

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