+ Reply to Thread
Results 1 to 10 of 10

Compile Error Type Mismatch

  1. #1
    Registered User
    Join Date
    06-23-2021
    Location
    Windsor UK
    MS-Off Ver
    Office365
    Posts
    15

    Compile Error Type Mismatch

    Evening Ladies & Gents,

    Wonder if some genius could help me out.

    I would classify myself as a less than a beginner as truth be told, I know nothing of VBA but have dabbled with some borrowed code to get things going on other spreadsheets.

    I have an inherited Excel sheet that uses VBA to communicate with GPI devices to get data and also to get screen shots.

    I have 2 laptops to use on 2 identical test stations BUT 1 laptop uses 32 bit and the other uses 64 bit Excel.

    For the main routine (changing settings and getting data etc) I have already used the Declare PtrSafe so that the macros run this stage without issue.

    However, the macro that gets the screen grab obviously fails with the above error on the 64 bit version of Excel. Section of the code below :

    When I run the macro, it stops at the "ArrayPtr(0) = VarPtr(length)" with the VarPtr highlighted. Also the actual Sub name is highlighted in yellow (if that helps at all)

    I even downloaded the Microsoft win32api helpfile but that confused me even more.

    Hoping that its a simple fix, I place myself in your hands !

    Thank You

    Tony
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Compile Error Type Mismatch

    Note: I tried to edit the post to put the code inline but Sucuri complained.

    ArrayPtr is declared as Long, but you are assigned the result of VarPtr which returns LongPtr in a 64-bit installation. If ArrayPtr is declared as LongPtr this error is resolved. Then you will need to declare ArrayPtr like this to be backward compatible:

    Please Login or Register  to view this content.
    Then I ran into problems with the viOpenDefaultRM call because you did not include that code.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-23-2021
    Location
    Windsor UK
    MS-Off Ver
    Office365
    Posts
    15

    Re: Compile Error Type Mismatch

    Hi 6StringJazzer,

    Thanks for the speedy reply. Unfortunately the full file size is just over 1MB hence the curtailed attachment.

    Would I place the above code at the beginning of the VBA module coding or on each error condition ?

    Thanks

    Tony

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Compile Error Type Mismatch

    The code I provided replaces the existing declaration of ArrayPtr (one line).

    I tried to put the code directly into your post but we have a security nanny that raised a false positive claiming it was an HTML injection attack. This happens more often than it should.

  5. #5
    Registered User
    Join Date
    06-23-2021
    Location
    Windsor UK
    MS-Off Ver
    Office365
    Posts
    15

    Re: Compile Error Type Mismatch

    Hi 6StringJazzer,

    Okay, having a wobbly head moment... the code you gave me... I placed that at the beginning of the subroutine along with the other declarations, I rem'd out the existing dim arrayptr statements. As there are 2 statements further down, arrayptr(0) and arrayptr(1) , do I need to replicate the code with (0) as well as (1) (If you get my drift) ?

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Compile Error Type Mismatch

    Your declaration, as well as my update, creates an array with a lower bound of 0 and an upper bound of 1 (2 elements). The statements farther down simply assign values to each of those two elements of the array. No other changes are needed.

    Also, the code you attached is truncated and does not show the entire sub.

    less than a beginner as truth be told, I know nothing of VBA
    To be candid the code you are working with here is rather advanced and your question about arrays does confirm that you may be in a bit over your head here.

  7. #7
    Registered User
    Join Date
    06-23-2021
    Location
    Windsor UK
    MS-Off Ver
    Office365
    Posts
    15

    Re: Compile Error Type Mismatch

    I totally agree with you ! The man who wrote this was a bit of a genius in this but he left some time ago. As I have inherited the workbook, it is my task to get this resolved otherwise IF the other laptop has an update applied to it and that goes full 64 bit, then our graphics capture is lost unless I start taking pictures on my phone and importing them into the test results.

    I'll copy the full subroutine into a new workbook and upload that. If that is okay with you ?

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Compile Error Type Mismatch

    Sure, that's fine.

    I do not have a 32-bit version of Excel to test with so any advice I give on code that will work with both versions will be somewhat theoretical.

  9. #9
    Registered User
    Join Date
    06-23-2021
    Location
    Windsor UK
    MS-Off Ver
    Office365
    Posts
    15

    Re: Compile Error Type Mismatch

    Hi 6StringJazzer,

    I think I have been working or trying to work on a corrupted version. Just tried it on a fresh copy of the master and when I run it with your added code, I am now getting a VISA error (which is not surprising as I don't have the hardware and associated software on my home machine). I'll try it in the morning when I have the full kit available.

    Thanks for your assistance,

    Tony

  10. #10
    Registered User
    Join Date
    06-23-2021
    Location
    Windsor UK
    MS-Off Ver
    Office365
    Posts
    15

    Re: Compile Error Type Mismatch

    Hi Jeff,

    Thanks a lot for your assist. Copied code to a "clean" version of the excel file and it works perfectly on the 64 bit system. Just tried on the 32 bit system and that works perfectly as well.

    All the best !

    Tony

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Compile Error Type Mismatch
    By Noannish in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2020, 06:22 PM
  2. Getting compile error 'type mismatch
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2017, 06:35 AM
  3. Getting compile error 'type mismatch'
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-14-2015, 09:27 AM
  4. [SOLVED] Getting compile error type mismatch
    By mso3 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-16-2015, 05:03 AM
  5. [SOLVED] Compile error: Type mismatch
    By jacob@thepenpoint in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-10-2014, 09:41 AM
  6. Compile Error - Type Mismatch
    By Will B in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2012, 11:17 AM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

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