Results 1 to 5 of 5

Thread: Removing characters from a textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    12
    I got a textbox with this content in it (note, the content changes each 15 second - it never stays the same).. It follows a system even though the content change constantly -17 characters, one space, some number (it can be 0 or it can be something like 384), yet another space and the rest after it can be completely different from time to time. Here's how the textbox content might look like:

    "habrufjsklimnejfu 56 fjoei fme 3 4jjrnf"

    Now what I need is a code to first remove the first 18 characters, "habrufjsklimnejfu ", leaving "56 fjoei fme 3 4jjrnf". Then it will scan the remaining text ("56 and some misc. text) and find out where the first space after the first numbers are - in this case right after the "6". Then it will remove everything behind the number "6", including the space.

    Leaving this text only:
    "56"

    How do I do that? Variables? strings..? I'm not good at variables and strings, so what I need is the complete code. And keep in mind that the text in the textbox can be something completely else the next time you run the code on it. It just follows the same pattern: 18 chars, some numbers (any number.. it can be 5 or 3984), a space and misc. characters following.

    I want to get rid of the 18 chars, the space and the misc. characters (c:

    Thanks in advance,
    Fredrik Stai
    [email protected]

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325

    try this:

    Code:
      
      Dim s_list() As String
      
      '' split a string delim. by " "
      s_list = Split(Me.txtBox.Text, " ")
      
      '' second bin or 56, zero based array
      Me.txtBox.Text = s_list(1)
    -Shickadance

  3. #3
    New Member
    Join Date
    May 2000
    Location
    Manchester, England
    Posts
    4

    Thumbs up

    Try this function...

    Private Function ExtractNumber(InputString As String) As Long
    Dim X As Long
    Dim C As String * 1
    Dim Spaces As Long
    Dim ExtractedString As String
    Spaces = 0
    X = 1
    ExtractedString = ""
    Do
    C = Mid(InputString, X, 1)
    If C >= "0" And C <= "9" Then
    ExtractedString = ExtractedString & C
    End If
    If C = " " Then
    Spaces = Spaces + 1
    End If
    DoEvents
    X = X + 1
    Loop Until Spaces = 2
    ExtractNumber = Val(ExtractedString)
    End Function
    Chris Morgan
    [email protected]

  4. #4
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325

    Red face

    My code is much more simple.
    -Shickadance

  5. #5
    New Member
    Join Date
    May 2000
    Location
    Manchester, England
    Posts
    4

    Thumbs up

    It sure is shorter! Thanks, I've learned something as well.

    Chris Morgan
    [email protected]

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