Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making a Backspace command button 2

Status
Not open for further replies.

SurvivorTiger

Programmer
Jul 9, 2002
265
US
hi everyone,
i'm making a calculator and i want to know how i can make a command button that erases the last digit that was typed in a label, any help would be Appreciated...
 
You could scan the text entry for the text and length then chop off the last character.

Like this:

Private Sub Command1_Click()
Dim gTxt as String, gLen as Integer
On Error GoTo Err
If Text1.Text <> &quot;&quot; Then
gLen = Len(Text1.Text)
gTxt = mid(Text1.Text, 1 , gLen - 1)
Text1.Text = gTxt
End If
Exit Sub

Err:
Exit Sub
End Sub

Let us know how it goes
Lightseeker
 
You will have hard time with the label as it does not receive the focus there for you will have no cursor position to backspace from. If you use the label you could get the caption and just trim the right character from the caption and then reset the caption, something like this.

Private Sub cmdLabelTrim_Click()
Label1.Caption = Left$(Label1.Caption, Len(Label1.Caption) - 1)
End Sub

If you use a textbox this code will work for you.

Private Sub cmdBackspace_Click()
Text1.SetFocus
SendKeys (Chr$(8))
End Sub

Hope this helps. [flip] If you choose to battle wits with the witless be prepared to lose.
[machinegun][hammer]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top