Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invalid qualifier when using string.remove()

Status
Not open for further replies.

manvee1

Programmer
Jul 17, 2002
22
US
my string (myStr) is read from a txt file into vb application like this...

'9999', '909', 2051, 'A', 1, 12345
'9999', '909', 2052, 'B', 1, 12346
...

i have 4000 of these records which im placing into a table.

problem is that the last column of the table is a number(4) hence 12345 wont fit.

so i've decided to chop off the last char with ...
newStr = Left(myStr, Len(myStr) - 1). and this works.
but my table now has 9 1234's

so ive decided to chop off the leading 1, (Len(myStr) - 5) that way ill have 4000 unique numbers.
eg
2345
2346
2347


Problem:
when i use the vb remove function from msdn help.
myStr2 = myStr.Remove(Len(myStr) - 5, 1)

i get an error 'invalid qualifier' on myStr

Is this a syntax err or is the vb string.remove()not avaliable?
 
I'm not aware of Remove as a string function in VB6. To remove the leftmost character from a string use the Right$ function:

myStr2 = Right$(myStr,Len(myStr)-1)

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
You will probably want to post this question in the appropriate forum, namely the C# Forum732
 
My application is written in vb.
Its a vb problem not c#. The problem being 'how do i remove the 5th to the last char from a string in vb'?

I guess ill just have to live with the duplicates from removing the last character in the string. It does not harm anything this time since this column is not used in anyway in this particular project....thanks again.
 
Did you try the solution I suggested above, which will remove the leftmost character? If you actually want to remove the 5th from last in a random length string, you can use the Replace function and the Mid$ function

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
>it looks like a c# procdeure

Actually it's a method on .NET framework class

And here's a simple VB implementation (note it does not include any bounds checking_:
Code:
[blue]Public Function vbRemove(strSource As String, ByVal StartIndex As Long, Optional ByVal Count As Long = 1) As String
        vbRemove = Left$(strSource, StartIndex - 1) + Right$(strSource, Len(strSource) - StartIndex - Count + 1)
End Function[/blue]

 
One of the problems with googling in the microsoft doc for vb6 answers is that you can often run into VB.Net stuff that looks like VB6 stuff by accident. You have to be careful of this.

<I Went back to look at msdn and it looks like a c# procdeure..

<Actually it's a method on .NET framework class

To expand a bit on strongm's answer: .Net has what they call the CLS, or common language specification. This means that there is a framework of object libraries that can be accessed equally by a number of languages, such as VB.Net and C#. So when you see a C# example, it could just as well be a VB.Net example, for they are both accessing the same code. Very often, what you are seeing is documentation for this .Net framework, with examples in one of the supported languages.

Bob
 
Thanks all.

Strongm's line of code ...

(vbRemove = Left$(strSource, StartIndex - 1) + Right$(strSource, Len(strSource) - StartIndex - Count + 1))

is PERFECT for the job! I think Strongm should work for microsoft and add this remove() to future vb code, that way lesser beings like me wont spend 2 much time searching:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top