Results 1 to 5 of 5

Thread: Why am I getting this error?

  1. #1

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

    Post

    Why does VB give me a Run-time Error 13 "Type Mismatch" when it executes this code?

    txtcust_name.Text = txtcust_name.Text - txtcust_name.SelText

    ------------------
    Ryan

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    I think you are trying to remove the selected text from textbox - this simply isn't possible the way you are doing it.

    You could do this;

    Text1.Text=Left(Text1.Text,Text1.SelStart)+Right(Text1.Text,Len(Text1.Text)-(Text1.SelStart+Text1.SelLength))

    That'll work.



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  3. #3
    Addicted Member
    Join Date
    Feb 2000
    Posts
    224

    Post

    VB does not belive in Mathematics with strings..

    If txtcust_name.text is full of numbers then
    this should work....

    txtcust_name.Text = val(txtcust_name.Text) - val(txtcust_name.SelText)

    else if they have string and what you are trying to acheive is to rip of txtcust_name.SelText string from txtcust_name.Text ...

    Then select the text using seltext and then change the seltext to ""

    ===============================


  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Er.. ok.. my way was a bit too complicated!! I forgot about the SelectText property..



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



  5. #5

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

    Post

    Ok, well thank you for your ideas, although I came up with my own. Here's what I did:

    Dim x As Integer
    x = Len(txtcust_name.Text) - Len(txtcust_name.SelText)
    txtcust_name.Text = Mid(txtcust_name.Text, 1, x)


    And that effectively truncates the selected text from the string. But thank you for you ideas. And I hope they change this in VB7. It would be so much easier to be able to do it how I wanted to.

    ------------------
    Ryan

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