Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

InStr function error driving me around the bend.

Discussion in 'Information Technology' started by DaBartman, Jul 28, 2006.

  1. DaBartman

    DaBartman
    Expand Collapse
    Guest

    I am quite puzzled by the error I when this function gets called:
    Runtime error "13"
    Type mismatch

    The error is triggered by the InStr function

    Public Function IsNoLimit(gn As String) As Boolean

    Dim gnp As String

    If InStr(gn, "No Limit", vbTextCompare) > 0 Then <<< offending line of
    code
    IsNoLimit = True
    Else
    IsNoLimit = False
    End If

    End Function

    All I want it to do is tell me if the string "No Limit" was found; InStr >0
    as in gn = " 5/10 No Limit Holdem" where InStr would be 6 or "Omaha8: Limit
    6/12" where InStr should be 0 as "No Limit" was not found within the search
    string gn.

    The help files tell me that the return data type of the InStr function is
    Varient (Long). I have tried using a variable to return the InStr function to
    (such as gnnl) and dimmsioning the variable to Varient and Long. The error
    has always been the same which is why you see the current code attempt above.
    Same error.

    Anyone out there have any ideas as to why I get this error and any solutions
    to it?

    Much thanks for reading this somewhat lengthly post,
    Bart
     
  2. Loading...

    Similar Threads Forum Date
    General Namdhari Join Sikh Mainstream Hard Talk Sep 15, 2015
    Politics “Untouchability Is An Instrument In The Hands Of The Upper Castes” Breaking News Oct 28, 2012
    World In Israel, Spate Of Ultra-Orthodox Incidents Rattle The Secular Mainstream Breaking News Jan 10, 2012
    General Great Sikh Instrumentalists: Music no vocals Videos Dec 7, 2011
    Multicultural Minstrel - Sikh-Aussie Dya Singh Gurmat Sangeet Nov 13, 2011

  3. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    Yes, that's confusing.

    The issue is that all 4 arguments of Instr() are optional, and you must
    include the first (the starting position) when you include the last (the
    compare type.)

    Try:
    If InStr(1, gn, "No Limit", vbTextCompare) > 0 Then

    Or perhaps just:
    IsNoLimit = (InStr(1, gn, "No Limit", vbTextCompare) = 0)

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "DaBartman" <DaBartman@discussions.microsoft.com> wrote in message
    news:3C193C95-510C-47DD-9F1E-6D29C8D8D5FF@microsoft.com...
    >I am quite puzzled by the error I when this function gets called:
    > Runtime error "13"
    > Type mismatch
    >
    > The error is triggered by the InStr function
    >
    > Public Function IsNoLimit(gn As String) As Boolean
    >
    > Dim gnp As String
    >
    > If InStr(gn, "No Limit", vbTextCompare) > 0 Then <<< offending line of
    > code
    > IsNoLimit = True
    > Else
    > IsNoLimit = False
    > End If
    >
    > End Function
    >
    > All I want it to do is tell me if the string "No Limit" was found; InStr
    > >0

    > as in gn = " 5/10 No Limit Holdem" where InStr would be 6 or "Omaha8:
    > Limit
    > 6/12" where InStr should be 0 as "No Limit" was not found within the
    > search
    > string gn.
    >
    > The help files tell me that the return data type of the InStr function is
    > Varient (Long). I have tried using a variable to return the InStr function
    > to
    > (such as gnnl) and dimmsioning the variable to Varient and Long. The error
    > has always been the same which is why you see the current code attempt
    > above.
    > Same error.
    >
    > Anyone out there have any ideas as to why I get this error and any
    > solutions
    > to it?
    >
    > Much thanks for reading this somewhat lengthly post,
    > Bart
     
  4. Matthias Klaey

    Matthias Klaey
    Expand Collapse
    Guest

    DaBartman <DaBartman@discussions.microsoft.com> wrote:

    >I am quite puzzled by the error I when this function gets called:
    >Runtime error "13"
    >Type mismatch
    >
    >The error is triggered by the InStr function
    >
    >Public Function IsNoLimit(gn As String) As Boolean
    >
    > Dim gnp As String
    >
    > If InStr(gn, "No Limit", vbTextCompare) > 0 Then <<< offending line of

    [...]

    Try If InStr(1, gn, "No Limit", vbTextCompare) > 0 Then

    If you use the compare option, you need to give the start argument.
    This is perhaps one of the weirdest synatx rules in VB, so don't feel
    bad :)

    HTH
    Matthias Kläy
    --
    www.kcc.ch
     
  5. DaBartman

    DaBartman
    Expand Collapse
    Guest

    Problem solved by both of you. Thanks,
    Bart

    "Matthias Klaey" wrote:

    > DaBartman <DaBartman@discussions.microsoft.com> wrote:
    >
    > >I am quite puzzled by the error I when this function gets called:
    > >Runtime error "13"
    > >Type mismatch
    > >
    > >The error is triggered by the InStr function
    > >
    > >Public Function IsNoLimit(gn As String) As Boolean
    > >
    > > Dim gnp As String
    > >
    > > If InStr(gn, "No Limit", vbTextCompare) > 0 Then <<< offending line of

    > [...]
    >
    > Try If InStr(1, gn, "No Limit", vbTextCompare) > 0 Then
    >
    > If you use the compare option, you need to give the start argument.
    > This is perhaps one of the weirdest synatx rules in VB, so don't feel
    > bad :)
    >
    > HTH
    > Matthias Kläy
    > --
    > www.kcc.ch
    >
    >
     
  6. david epsom dot com dot au

    david epsom dot com dot au
    Expand Collapse
    Guest

    vbTextCompare is the default value in Access.

    If InStr(gn,"No Limit")

    This is what the line:
    Option Compare Database
    at the top of every module means.

    (david)

    "DaBartman" <DaBartman@discussions.microsoft.com> wrote in message
    news:3C193C95-510C-47DD-9F1E-6D29C8D8D5FF@microsoft.com...
    >I am quite puzzled by the error I when this function gets called:
    > Runtime error "13"
    > Type mismatch
    >
    > The error is triggered by the InStr function
    >
    > Public Function IsNoLimit(gn As String) As Boolean
    >
    > Dim gnp As String
    >
    > If InStr(gn, "No Limit", vbTextCompare) > 0 Then <<< offending line of
    > code
    > IsNoLimit = True
    > Else
    > IsNoLimit = False
    > End If
    >
    > End Function
    >
    > All I want it to do is tell me if the string "No Limit" was found; InStr
    > >0

    > as in gn = " 5/10 No Limit Holdem" where InStr would be 6 or "Omaha8:
    > Limit
    > 6/12" where InStr should be 0 as "No Limit" was not found within the
    > search
    > string gn.
    >
    > The help files tell me that the return data type of the InStr function is
    > Varient (Long). I have tried using a variable to return the InStr function
    > to
    > (such as gnnl) and dimmsioning the variable to Varient and Long. The error
    > has always been the same which is why you see the current code attempt
    > above.
    > Same error.
    >
    > Anyone out there have any ideas as to why I get this error and any
    > solutions
    > to it?
    >
    > Much thanks for reading this somewhat lengthly post,
    > Bart
     

Share This Page