+ Reply to Thread
Results 1 to 3 of 3

Weird Error 13 type mismatch: it's there then it's not

  1. #1
    Registered User
    Join Date
    08-18-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    1

    Weird Error 13 type mismatch: it's there then it's not

    Hi

    I'm new to VBA. I'm having a very weird problem which I think is down to how the Visual Basic editor works but don't know enough to track further...has anyone seen something similar before?

    My project has an interface class iFoo. This is implemented by several classes cBarA, cBarB and cBarC.

    At runtime a factory function creates the appropriate class according to an input parameter. Ie:
    Please Login or Register  to view this content.

    (Real World Details: The real app reads a log file and the classes represent different types of events in the logs. Each line in the log is passed to the factory which returns the appropriate event)

    The worksheet contains several sheets with test input. If I open the worksheet and try to run the test I get a type mismatch error when the created object is assigned to the interface type variable. However if I go to any of the class modules that implement the interface, remove the "implements iFoo" line and retype it then run the test on exactly the same data it works!

    There are several inputs sheets and I get the same results with all of them.

    It doesn't matter if I run the test once, twice or n times after opening, it won't work until I have removed and replaced the implements line in any one of the class modules. Compiling doesn't seem to make any difference: if I compile after opening without making the change it doesn't fix it, but if I compile after making the change it doesn't break it either. If I save the project and worksheet in the working state (ie after replacing the implements line) it will be broken again when I reopen it.

    It looks like when the file is first opened for some reason VBA doesn't pick up the Implements statement and throws a type mismatch, then reentering the statement causes the interpreter to update it and the statement is picked up. I assume the code is compiled/interpreted differently after a change in the editor than when the file is saved, but I don't know enough about the difference to help me solve me problem.

    Can anyone give me any pointers?

    Many thanks (and if you've read this far well done!)

    Liz
    Last edited by brokenbetty; 08-18-2009 at 05:33 PM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,063

    Re: Weird Error 13 type mismatch: it's there then it's not

    I can't see anything obviously wrong there (I assume the 'Else if' rather than 'ElseIf' is a typo). How are you calling the test sub? Also, if you put that code into a new blank workbook does the same thing occur? It works fine for me in a quick test in XL2003.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,485

    Re: Weird Error 13 type mismatch: it's there then it's not

    Also you might want to try this free addin.
    http://www.appspro.com/Utilities/CodeCleaner.htm
    Cheers
    Andy
    www.andypope.info

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1