attempt to use the String Class Member "Remove" restults in error

J

Jeff

Ok, I know this should be simple, I am trying to use the String Class
Member "Remove" like so:

1 Dim tmp1 As String
2 tmp1 = txtBox1.Value
3 tmp1 = tmp1.Remove(0, 7)
4 txtBox2.Value = tmp1

I've got lots of experience programming in C and C++ and it seams like
I just need the equivilent of "#include string;" But I'm still
learning vb, and I can't seam to find a way to do so anywhere.

The above code runs on form_load() and is suppose to remove the first 7
characters from a 14 character string. But when the form loads I get an
error stating: "Compile error: Invalid qualifier" and it highlights
the tmp1 just before the period on line 3 above.

So... what am I doing wrong here?
 
G

Guest

Hey Jeff, to include reference libraries, in the VB Editor, go to
Tools-->References. Check the box next to the library you want to include.

If your string is always 14 characters long, you can use the Right or Mid
function:

txtBox2.Value = Right(txtBox1.Value,7)

If the length varies, use the above function with the Len function.
 
G

Graham Mandeno

Hi Jeff

Different languages - different syntaxes and methods.

In VB, a String is not a class and has no methods ("members"). Instead you
manipulate string contents using built-in and user-defined functions.
Useful built-in functions for strings include:
Len, Mid, Left, Right, InStr, InStrRev, Replace
There are many more - you can find out about these and others in the online
help.

There is no Remove function, but you can achieve the same thing easily
enough:
txtBox1 = Mid(txtBox1, 8)
will replace txtBox1.Value (Value is the default property of a textbox) with
the existing contents starting at the 8th character. (Note that string
indexing starts at 1, not 0)

If you would feel more comfortable with a Remove function, you can write
your own:

Public Function Remove (sInput as String, iStart as Integer, _
iLen as Integer) as String
If Len(sInput) > iLen Then
If iStart<=1 then
Remove = Mid(sInput, iLen+1)
Else
Remove = Left(sInput, iStart-1) & Mid(sInput, iStart + iLen)
End If
Else
Remove = ""
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top