Results 1 to 18 of 18

Thread: Stupid inherits issue, or not?. [resolved]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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.

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Stupid inherits issue, or not?.

    Hi
    Activate Option Strict On

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: Stupid inherits issue, or not?.

    Well, i added it.. but no luck.

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    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."

  5. #5
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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.

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: Stupid inherits issue, or not?.

    Ok, give me a min and I will post the code.

  9. #9
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    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:
    1. 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

  10. #10
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Stupid inherits issue, or not?.

    VB Code:
    1. 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

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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...

  12. #12
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    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

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    Re: Stupid inherits issue, or not?.

    Quote Originally Posted by <ABX
    VB Code:
    1. 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.

  14. #14
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Stupid inherits issue, or not?.

    Then you use
    VB Code:
    1. CType("myString", String)

    You could also use DirectCast ;p

    Edit: here is the full statement just in case

    VB Code:
    1. 'you can use either of these
    2. Msgbox InStr(startIndex, strbuffer, Ctype("MyString", String))
    3. 'DirectCast Is quicker but it MUST BE A STRING as it does not do type checking
    4. 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

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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.

  16. #16
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    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:
    1. Private Function isSpace(ByVal var As String) As Boolean
    2.         If var = Chr(32) Then isSpace = True
    3.     End Function
    4.  
    5.     Private Function isLetter(ByRef var As String) As Boolean
    6.  
    7.         If Asc(var) >= 65 And _
    8.             Asc(var) <= 90 Or _
    9.             Asc(var) >= 97 And _
    10.             Asc(var) <= 122 Then
    11.  
    12.             isLetter = True
    13.         End If
    14.  
    15.     End Function

    could be replaced with
    VB Code:
    1. Char.IsLetter("x"c)
    2. 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

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2000
    Posts
    770

    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
    Modulization (splitting code up into classes, blocks) ok, you still do alot in your form.
    Identing: good.

    VB Code:
    1. Private Function isSpace(ByVal var As String) As Boolean
    2.         If var = Chr(32) Then isSpace = True
    3.     End Function
    4.  
    5.     Private Function isLetter(ByRef var As String) As Boolean
    6.  
    7.         If Asc(var) >= 65 And _
    8.             Asc(var) <= 90 Or _
    9.             Asc(var) >= 97 And _
    10.             Asc(var) <= 122 Then
    11.  
    12.             isLetter = True
    13.         End If
    14.  
    15.     End Function

    could be replaced with
    VB Code:
    1. Char.IsLetter("x"c)
    2. 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.

  18. #18
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622

    Re: Stupid inherits issue, or not?. [resolved]

    To use that code....

    first add
    VB Code:
    1. Imports System.Globalization


    It can be shortened to:
    VB Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width