Adding Text to a Text Box
How can you use a command button in Visual Basic 6 to add a new character to a specified text box without erasing the existing charactors?Also how can you use a command button to erase the last character you typed in a specified text box rather than all of it?
Re: Adding Text to a Text Box
Private Sub Command1_Click()
Text1.Text = Text1.Text & "xx"
End Sub
Private Sub Command2_Click()
Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
End Sub
Re: Adding Text to a Text Box
Ok that works great thanks a lot. The only problem is when the text box is empty and I try to press the command button to delete some more text I get a run time error that reads:
Run-time error '5':
Invalid procedure call or argument
Is there anyway to make it so that nothing happens when the text box has nothing inside it rather than getting that error each time?
Thanks,
Darren
Re: Adding Text to a Text Box
Put some error trapping in.
Either
VB Code:
Private Sub Command2_Click()
On Error Resume Next
Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
End Sub
Or
VB Code:
Private Sub Command2_Click()
If Text1.Text = "" Then
Exit Sub
Else
Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Re: Adding Text to a Text Box
This is a same one of above
Private Sub Command1_Click()
Text1.Text = Text1.Text & "xx"
End Sub
Private Sub Command2_Click()
If Not Text1.Text = "" Then
Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub