-
Stupid inherits issue, or not?. [resolved]
I have 3 classes
Public Class Form1
Public Class Search
Public Class XYZ
1. The Search class is a multithreaded object that is called from a method in Form1.
2. The XYZ class contains a method that is called from Search.
3. XYZ contains the InStr() function, however, VB.NET says:
"Overload resolution failed because no accessible 'InStr' can be called without a narrowing conversion"
So, im not sure if this is an inheritance issue or not. Does anyone know what i'm doing wrong? Thanks.
-
Re: Stupid inherits issue, or not?.
Hi
Activate Option Strict On
Regards
Jorge
-
Re: Stupid inherits issue, or not?.
Well, i added it.. but no luck.
-
Re: Stupid inherits issue, or not?.
Well without code its going to be complex.
-
Re: Stupid inherits issue, or not?.
To answer the question asked, yes it's an inheritance issue.
To answer the unasked question of why.... InStr is a built in VB function. And you are ovberloading it. Presumably, you've overloaded it such that when it's called, it can't tell which one to call. It needs to "narrow" down the possiblities.
Tg
-
Re: Stupid inherits issue, or not?.
well I imagine you are passing a string to InStr()?
why not just use the IndexOf method of the string itself, which is the "VB.NET" way to do it. InStr is more for backwards compatibility.
-
Re: Stupid inherits issue, or not?.
techgnome
Thanks for answering the un-asked Why part. Now, How can I go about "Narrowing down" the possibilities.. lol. I feel stupid.
kleinma
indexOf is great, but is limited in its abilities. I need the functionality of InStr() for what i'm doing. As far as I know, indexOf is not a replacement for InStr(). indexOf was added because of how strings are handled in VB.NET (you know, like C strings.).. I suppose.
-
Re: Stupid inherits issue, or not?.
Ok, give me a min and I will post the code.
-
Re: Stupid inherits issue, or not?.
You can narrow down the possibilties by explicitly casting your datatypes to the expected type for the signature
Just to let you know.... the vb6 instr functionality (in .net) is basiclly wrapping this:
VB Code:
MsgBox(System.Globalization.CultureInfo.CurrentCulture.CompareInfo.IndexOf("TeSt", "S"c, 0, Globalization.CompareOptions.IgnoreCase))
String.InStr(also uses the CompareInfo Class to compare strings)
Using compareinfo gives you even more control...
if you still want to use vb6 InStr, post the line that you use it.. and I'll help you fix it...
-
Re: Stupid inherits issue, or not?.
VB Code:
otPos = InStr(currentPos, strBuffer, "<"c)
should fix it.
the c after the string... casts it to a char (you will need this when using option strict)
-
Re: Stupid inherits issue, or not?.
what is it that InStr does that IndexOf doesn't? I am curious. I am pretty sure IndexOf has the same capabilities...
-
Re: Stupid inherits issue, or not?.
The only think i can think of is that It allows case-insenstivity IndexOf (String.IndexOf) does not.. but in his code he isnt using it.
So, in this particular case... nothing and with CompareInfo.IndexOf you can do more than InStr
-
Re: Stupid inherits issue, or not?.
Quote:
Originally Posted by <ABX
VB Code:
otPos = InStr(currentPos, strBuffer, "<"c)
should fix it.
the c after the string... casts it to a char (you will need this when using option strict)
That might work for that particular one, but not the ones with multiple characters.
-
Re: Stupid inherits issue, or not?.
Then you use
VB Code:
CType("myString", String)
You could also use DirectCast ;p
Edit: here is the full statement just in case
VB Code:
'you can use either of these
Msgbox InStr(startIndex, strbuffer, Ctype("MyString", String))
'DirectCast Is quicker but it MUST BE A STRING as it does not do type checking
Msgbox InStr(startIndex, strbuffer, DirectCast("MyString", String))
-
Re: Stupid inherits issue, or not?.
Quote:
Originally Posted by <ABX
The only think i can think of is that It allows case-insenstivity IndexOf (String.IndexOf) does not.. but in his code he isnt using it.
So, in this particular case... nothing and with CompareInfo.IndexOf you can do more than InStr
Actually, the code does use both Binary compare and Text compare in a few parts.. Anyway, i just found out that if i specify a compare method on the InStr methods that dont have them already specified then it will work and the ugly error goes away.
So, what did you guys think of my code?
Thanks for the help BTW.... I appreciate it.
-
Re: Stupid inherits issue, or not?.
Ah.. i missed the form... (i didnt open the project)
what i think:
Not bad...
You may find using Regular Expressions a better solution for doing this...
I still would prefer you to use IndexOf (as it is the vb.net way, and it still is using it anyway) (same with mid. (String.Substring)
You are using Option Explict, Option Strict :D
Modulization (splitting code up into classes, blocks) ok, you still do alot in your form.
Identing: good.
VB Code:
Private Function isSpace(ByVal var As String) As Boolean
If var = Chr(32) Then isSpace = True
End Function
Private Function isLetter(ByRef var As String) As Boolean
If Asc(var) >= 65 And _
Asc(var) <= 90 Or _
Asc(var) >= 97 And _
Asc(var) <= 122 Then
isLetter = True
End If
End Function
could be replaced with
VB Code:
Char.IsLetter("x"c)
Char.IsWhiteSpace("x"c)
Its pretty good :D
-
Re: Stupid inherits issue, or not?.
Quote:
Originally Posted by <ABX
Ah.. i missed the form... (i didnt open the project)
what i think:
Not bad...
You may find using
Regular Expressions a better solution for doing this...
I still would prefer you to use IndexOf (as it is the vb.net way, and it still is using it anyway) (same with mid. (String.Substring)
You are using Option Explict, Option Strict :D
Modulization (splitting code up into classes, blocks) ok, you still do alot in your form.
Identing: good.
VB Code:
Private Function isSpace(ByVal var As String) As Boolean
If var = Chr(32) Then isSpace = True
End Function
Private Function isLetter(ByRef var As String) As Boolean
If Asc(var) >= 65 And _
Asc(var) <= 90 Or _
Asc(var) >= 97 And _
Asc(var) <= 122 Then
isLetter = True
End If
End Function
could be replaced with
VB Code:
Char.IsLetter("x"c)
Char.IsWhiteSpace("x"c)
Its pretty good :D
IsLetter and IsWhiteSpace was originally for vb6. Thanks for pointing the built in features out.
As for the regular expressions, a friend wrote a function to do almost the same thing as mine, except it was painfully slow. But it was a good idea at the time. My method is a linear solution that doesn't add overhead. It needs to be as fast as possible because I have to perform this on hundreds of files.
As for the indexOf, I would, but I am still not sure how to include the CompareMethod parameter. How do I do that again?
Thanks!
-
Re: Stupid inherits issue, or not?. [resolved]
To use that code....
first add
VB Code:
Imports System.Globalization
It can be shortened to:
VB Code:
MsgBox(CultureInfo.CurrentCulture.CompareInfo.IndexOf(strbuffer, ">"c, startIndex, CompareOptions.IgnoreCase))
also not that in vb.net 0 is the start of a string in vb6 it was 1