Results 1 to 5 of 5

Thread: Adding Text to a Text Box

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    41

    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?

  2. #2
    Addicted Member thiru_rajamani's Avatar
    Join Date
    Aug 2004
    Location
    Chennai,India
    Posts
    214

    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
    Thanks
    Raj

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    41

    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

  4. #4
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383

    Re: Adding Text to a Text Box

    Put some error trapping in.
    Either
    VB Code:
    1. Private Sub Command2_Click()
    2.     On Error Resume Next
    3.     Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
    4. End Sub
    Or
    VB Code:
    1. Private Sub Command2_Click()
    2. If Text1.Text = "" Then
    3.     Exit Sub
    4. Else
    5.     Text1.Text = Left$(Text1.Text, Len(Text1.Text) - 1)
    6. End If
    7. End Sub

  5. #5
    Addicted Member thiru_rajamani's Avatar
    Join Date
    Aug 2004
    Location
    Chennai,India
    Posts
    214

    Wink 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
    Thanks
    Raj

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