+ Reply to Thread
Results 1 to 3 of 3

Excel 2007 : Compile error in passing variables to a function

  1. #1
    Registered User
    Join Date
    10-08-2011
    Location
    NY, US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Compile error in passing variables to a function

    Greetings,

    when trying to call the following function "ComplexOp1()", I get the following message: "Compile error: Only user-defined types in public object modules can be coerced to or from a variant or passed to late-bound function". The variable "CNum2" in the line "Case 1: cNum3 = cNumConj(cNum2) " gets highlighted by the compiler.

    here is the function ComplexOp1:

    Please Login or Register  to view this content.
    here's the "set_cNum" function that gets called in "ComplexOp1":

    Please Login or Register  to view this content.
    --Does anyone now what the error message means? Thanks.
    Last edited by CFA-VBA; 10-13-2011 at 11:31 AM. Reason: enclosure of code in code tags for proper display

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Compile error in passing variables to a function

    Welcome to the forum! A couple of things:
    1) please re-read the forum rules about how to enclose your code in code tags so it will display properly.
    2) Take a minute to define rP1 and iP1 to do.

    You have not defined them properly. Take a look at the help topic on data conversion functions for better understanding.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Registered User
    Join Date
    10-08-2011
    Location
    NY, US
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Compile error in passing variables to a function

    Hi tlafferty,

    the previous code has been tagged now; in regards to point #2, when you say "define rP1 and iP1", you mean defining their datatype when passing them into function "ComplexOp2" like this ?
    Please Login or Register  to view this content.
    Also, here's the datatype defined prior for cNum that uses rP1 & iP1 in functions that wasn't included in my first post:

    Please Login or Register  to view this content.

+ 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