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
Printable View
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
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.
:D
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
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 ""
===============================
Er.. ok.. my way was a bit too complicated!! I forgot about the SelectText property..
:D
------------------
Mark "Buzby" Beeton
VB Developer
[email protected]
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