+ Reply to Thread
Results 1 to 9 of 9

Converting variant return type from evaluate to integer

  1. #1
    Registered User
    Join Date
    10-07-2009
    Location
    Westford, MA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Converting variant return type from evaluate to integer

    I would like to get the return value for an evaluate statement which is a variant data type, convert it to an integer and do some computation. I have 4 test programs, the first 3 all work, the 4ths does not.

    The first sd_test(returns 1) and st_test1(returns 1) demonstrate that my evaluate statement is correct and works,

    sd_test2(returns 3) shows that I can convert a variant to an integer

    in sd_test3(returns #VALUE!) I try to put both together and it doesn't work?
    any help? thanks paul



    Please Login or Register  to view this content.
    Last edited by NBVC; 10-07-2009 at 12:24 PM. Reason: Solved

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Converting variant return type from evaluate to integer

    Hi

    I expect Evaluate is returning an array so you need to reference the array element to pass to the CInt function:

    Please Login or Register  to view this content.
    Richard
    Richard Schollar
    Microsoft MVP - Excel

  3. #3
    Registered User
    Join Date
    10-07-2009
    Location
    Westford, MA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Converting variant return type from evaluate to integer

    that didn't work, I got a compile error, the fact that
    I can set
    Dim X as variant
    x = evaluate

    seems to state that evaulat isn't returning an array or else X would need to be an array, however I tried with both subscripts of x[0] and x[1] neither worked

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Converting variant return type from evaluate to integer

    Variants can hold arrays - the code works for me once my amendment has been put through. Your table header row isn't in a row past 32767 is it?

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Converting variant return type from evaluate to integer

    If your compile error was a syntax error, did you use square brackets rather than standard ones? Richard's code is correct.
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    10-07-2009
    Location
    Westford, MA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Converting variant return type from evaluate to integer

    Yes thanks, I"m a c/c++ programmer and I assumed that an array subscript would be [] not (), so I put in [] and it failed. Thanks for your patience

  7. #7
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Converting variant return type from evaluate to integer

    No worries - glad that's sorted.

    Wish I was clever enough to be a C/C++ programmer!

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Converting variant return type from evaluate to integer

    Easy mistake to make!
    (just a bit gallling to have to admit Richard was right... )

  9. #9
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: Converting variant return type from evaluate to integer

    Quote Originally Posted by romperstomper View Post
    (just a bit gallling to have to admit Richard was right... )
    Cheeky bugger!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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