-
Feb 3rd, 2005, 12:38 PM
#1
Thread Starter
Fanatic Member
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.
Last edited by nkad; Feb 3rd, 2005 at 02:31 PM.
-
Feb 3rd, 2005, 12:53 PM
#2
Re: Stupid inherits issue, or not?.
Hi
Activate Option Strict On
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Feb 3rd, 2005, 01:15 PM
#3
Thread Starter
Fanatic Member
Re: Stupid inherits issue, or not?.
Well, i added it.. but no luck.
-
Feb 3rd, 2005, 01:30 PM
#4
Re: Stupid inherits issue, or not?.
Well without code its going to be complex.
"The dark side clouds everything. Impossible to see the future is."
-
Feb 3rd, 2005, 01:33 PM
#5
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
-
Feb 3rd, 2005, 01:36 PM
#6
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.
-
Feb 3rd, 2005, 01:44 PM
#7
Thread Starter
Fanatic Member
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.
-
Feb 3rd, 2005, 01:51 PM
#8
Thread Starter
Fanatic Member
Re: Stupid inherits issue, or not?.
Ok, give me a min and I will post the code.
-
Feb 3rd, 2005, 01:59 PM
#9
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...
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Feb 3rd, 2005, 02:05 PM
#10
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)
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Feb 3rd, 2005, 02:08 PM
#11
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...
-
Feb 3rd, 2005, 02:13 PM
#12
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
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Feb 3rd, 2005, 02:15 PM
#13
Thread Starter
Fanatic Member
Re: Stupid inherits issue, or not?.
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.
-
Feb 3rd, 2005, 02:25 PM
#14
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))
Last edited by <ABX; Feb 3rd, 2005 at 02:30 PM.
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Feb 3rd, 2005, 02:29 PM
#15
Thread Starter
Fanatic Member
Re: Stupid inherits issue, or not?.
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.
-
Feb 3rd, 2005, 02:46 PM
#16
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
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
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Feb 3rd, 2005, 02:57 PM
#17
Thread Starter
Fanatic Member
Re: Stupid inherits issue, or not?.
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
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
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!
Last edited by nkad; Feb 3rd, 2005 at 03:07 PM.
-
Feb 3rd, 2005, 05:06 PM
#18
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
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|