Results 1 to 4 of 4

Thread: Checking 4 spaces behind the cursor

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Unhappy

    I have a multi-line text box. I cannot assume the person typeing text is at the end of it and it could be as many as 500 or so lines. I need to be able to check and see if the four characters before the cursor are spaces, and if they are, delete them all. This needs to happen when the user hits the backspace key. I've captured the backspace but I don't know how to check the previous 4 characters. Anybody have any help?
    Thanks,
    Chris

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    http://www.mvps.org/vbnet/code/texta...urrentline.htm

    ---------- Forget about the api stuff, this is better!
    Text1.SelStart

    this will help you to get the position of the cursor I think, then just check with
    Code:
    If Mid(Text1.Text, Text1.SelStart - 3, 4) = "    " Then
    'Method to remove the spaces, I can't use split because I have no VB6
    End If

    hey, add me to ICQ please! 18818940

    Have Fun!

    [Edited by Jop on 09-07-2000 at 02:21 PM]
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2000
    Location
    Virginia
    Posts
    55

    Talking LifeSaver

    That's the second time you have helped me out. I can't tell you how much I appreciate it. I kept trying text1.seltext - 3 and obviously I kept getting errors. Thank you very much.

    ?What do you mean add you to ICQ?
    Thanks,
    Chris

  4. #4
    Guest
    I think he means for you to add him to your ICQ list.

    Jop: Incase you're interested, here is the VB5 equv. of Split.
    Code:
    Public Function Split(ByVal sIn As String, Optional sDelim As _
          String, Optional nLimit As Long = -1, Optional bCompare As _
           VbCompareMethod = vbBinaryCompare) As Variant
        Dim sRead As String, sOut() As String, nC As Integer
        If sDelim = "" Then
            Split = sIn
        End If
        sRead = ReadUntil(sIn, sDelim, bCompare)
        Do
            ReDim Preserve sOut(nC)
            sOut(nC) = sRead
            nC = nC + 1
            If nLimit <> -1 And nC >= nLimit Then Exit Do
            sRead = ReadUntil(sIn, sDelim)
        Loop While sRead <> ""
        ReDim Preserve sOut(nC)
        sOut(nC) = sIn
        Split = sOut
    End Function
    
    Public Function ReadUntil(ByRef sIn As String, _
          sDelim As String, Optional bCompare As VbCompareMethod _
        = vbBinaryCompare) As String
        Dim nPos As String
        nPos = InStr(1, sIn, sDelim, bCompare)
        If nPos > 0 Then
            ReadUntil = Left(sIn, nPos - 1)
            sIn = Mid(sIn, nPos + Len(sDelim))
        End If
    End Function

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