Click to See Complete Forum and Search --> : Deleting a character from a textbox
Gimpster
Nov 5th, 1999, 04:57 AM
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
corneslen@hotmail.com
ICQ# 47799046
QWERTY
Nov 5th, 1999, 05:03 AM
If you want to delete last one (or any number of character at the end) you could use Left Function
'Text1="QWERTY"
Text1.text=Left(Text1.text,4)
'Text1="QWER"
To delete any number of characters from the begining Right Function
'text1="QWERTY"
Text1.Text=Right(text1.text,4)
'text1="ERTY"
------------------
Visual Basic Programmer
-----------------
PolComSoft
You will hear a lot about it.
ChrisJackson
Nov 5th, 1999, 05:04 AM
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).]
QWERTY
Nov 5th, 1999, 05:07 AM
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).]
Gimpster
Nov 5th, 1999, 05:15 AM
Ok, thanks a lot.
------------------
Ryan
corneslen@hotmail.com
ICQ# 47799046
DiGiTaIErRoR
Nov 5th, 1999, 08:39 AM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.