Results 1 to 6 of 6

Thread: Deleting a character from a textbox

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    How can I delete a single character from a text box? Say, I have 5 characters in a text box, and I want to delete just the last one, so that I'll have 4 characters in the text box after running the code. How would I do that? Please include some code. Thanks.

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    If you want to delete last one (or any number of character at the end) you could use Left Function
    Code:
    'Text1="QWERTY"
    Text1.text=Left(Text1.text,4)
    'Text1="QWER"
    To delete any number of characters from the begining Right Function
    Code:
    'text1="QWERTY"
    Text1.Text=Right(text1.text,4)
    'text1="ERTY"
    ------------------
    Visual Basic Programmer
    -----------------
    PolComSoft
    You will hear a lot about it.


  3. #3
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Hi.

    This code should do the trick.

    If Len(Text1) > 0 Then
    Text1.Text = Left(Text1.Text, (Len(Text1.Text) - 1))
    Else
    MsgBox "Nothing to delete!"
    End If


    [This message has been edited by ChrisJackson (edited 11-05-1999).]

  4. #4
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    You can also take a look on Mid Statement in VB help.

    ------------------
    Visual Basic Programmer
    -----------------
    PolComSoft
    You will hear a lot about it.



    [This message has been edited by QWERTY (edited 11-05-1999).]

  5. #5

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Ok, thanks a lot.

    ------------------
    Ryan
    [email protected]
    ICQ# 47799046

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    that's all good if it's on the ends.
    but if you just want one code for everything try this:
    say we have abcde in a textbox and we want to replace c
    <code>
    Private Sub Command1_Click()
    Replace$ = "c"
    n = InStr(Text1.Text, Replace$)
    Text2.Text = Left$(Text1.Text, n - 1) & text3.Text = Right$(Text1.Text, Len(Text1.Text) - n)
    End Sub
    </code>
    This will only replace the first C if you want you could loop it until instr(text1, replace$) = 0 and use Ucase$ or lcase$ to make sure you get ALL C or c.


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