Type Mismatch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ColinWard

    Type Mismatch

    I am using the function below in the exit event of a text box and to
    test it I am using/////. However, this gives me a type mismatch error on
    Len(strToCheck) . Is / considered a special character or am I
    implementing this function incorrectly?

    --Code Start--
    Public Function IsClean(strToCh eck) As Boolean

    Dim lng As Long
    Dim bln As Boolean

    If Len(strToCheck) > 0 Then
    For lng = 1 To Len(strToCheck)
    Select Case Asc(Mid$(strToC heck, lng, 1))
    Case 65 To 90
    ' Letters A to Z
    Case 97 To 122
    ' Letters a to z
    Case Else
    bln = True
    Exit For
    End Select
    Next lng
    End If
    IsClean = Not bln
    End Function
    --Code End--

    Thanks

    Colin



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Brendan Reynolds

    #2
    Re: Type Mismatch

    You haven't declared the data type of the argument 'strToCheck', Colin, so
    it will default to Variant. What if you explicitly declare it as String -
    does that solve the problem?

    --
    Brendan Reynolds

    "ColinWard" <jetfighter3@ho tmail.com> wrote in message
    news:403f565e$0 $193$75868355@n ews.frii.net...[color=blue]
    > I am using the function below in the exit event of a text box and to
    > test it I am using/////. However, this gives me a type mismatch error on
    > Len(strToCheck) . Is / considered a special character or am I
    > implementing this function incorrectly?
    >
    > --Code Start--
    > Public Function IsClean(strToCh eck) As Boolean
    >
    > Dim lng As Long
    > Dim bln As Boolean
    >
    > If Len(strToCheck) > 0 Then
    > For lng = 1 To Len(strToCheck)
    > Select Case Asc(Mid$(strToC heck, lng, 1))
    > Case 65 To 90
    > ' Letters A to Z
    > Case 97 To 122
    > ' Letters a to z
    > Case Else
    > bln = True
    > Exit For
    > End Select
    > Next lng
    > End If
    > IsClean = Not bln
    > End Function
    > --Code End--
    >
    > Thanks
    >
    > Colin
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]


    Comment

    • Mike Storr

      #3
      Re: Type Mismatch

      Try either declaring strToCheck as a String, or force it to one using
      Len(CStr(strToC heck)).

      Mike Storr



      "ColinWard" <jetfighter3@ho tmail.com> wrote in message
      news:403f565e$0 $193$75868355@n ews.frii.net...[color=blue]
      > I am using the function below in the exit event of a text box and to
      > test it I am using/////. However, this gives me a type mismatch error on
      > Len(strToCheck) . Is / considered a special character or am I
      > implementing this function incorrectly?
      >
      > --Code Start--
      > Public Function IsClean(strToCh eck) As Boolean
      >
      > Dim lng As Long
      > Dim bln As Boolean
      >
      > If Len(strToCheck) > 0 Then
      > For lng = 1 To Len(strToCheck)
      > Select Case Asc(Mid$(strToC heck, lng, 1))
      > Case 65 To 90
      > ' Letters A to Z
      > Case 97 To 122
      > ' Letters a to z
      > Case Else
      > bln = True
      > Exit For
      > End Select
      > Next lng
      > End If
      > IsClean = Not bln
      > End Function
      > --Code End--
      >
      > Thanks
      >
      > Colin
      >
      >
      >
      > *** Sent via Developersdex http://www.developersdex.com ***
      > Don't just participate in USENET...get rewarded for it![/color]


      Comment

      • ColinWard

        #4
        Re: Type Mismatch


        Thank you both for your replies. I tried Brendan's solution this morning
        before I posted the original message and for some reason it did not
        work. so then I tried Brendan's and forcing it to convert to a string
        was what I needed.

        Thank you both for your replies

        Colin


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        Working...