Results 1 to 4 of 4

Thread: Function "Type mismatch" Error

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    24

    Question

    I write this function

    Public Function CheckWord(RTFName As RichTextBox)
    .
    .
    .
    .
    end Function

    when I call it from a form like this :

    call CheckWord (RichTextBox1)

    I got an error "Type mismatch" on the line in the form
    what goes wrong ?

    Thanks
    Gil

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    24
    Sorry I forgot

    When You call a function like this you need
    to place the "call" word

    Call CheckWord(RTFbox)

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Is there some reason that you can't just pass RichTextBox1.Text? With a function name of CheckWord it doesn't seem that you would need to access any of the other properties.

    If you must pass the control, do this:

    Code:
    Public Function CheckWord(RTFName As Object)
    Dim rtfn As RichTextBox
    Set rtfn = RTFName

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    And I forgot to mention that you also have to type cast the function, i.e. Public Function CheckWord(RTFName As RichTextBox) As SOMETHING

    Also, after looking into the matter, I realize that your original declaration (plus the cast) will work. I wrote a quick test with CheckWord returning the contents of RTFName.Text.
    Code:
    Private Sub Command1_Click()
       Text1.Text = CheckWord(RichTextBox1)
    End Sub
    
    Private Function CheckWord(RTFName As RichTextBox) As String
       CheckWord = RTFName.Text
    End Function
    I tried leaving the "As String" off to see if it would cause the error. No error, but also no returned string. Maybe this will still give you something to try.

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