Link to home
Start Free TrialLog in
Avatar of MohdAsalah
MohdAsalah

asked on

What is the problem with this code -Under ATL- ?

HI all,
Can anybody tell me what is the problem with this code??
 _variant_t v1,v2;
 v1 = Function1("string1") ;
 v2 = Function2("string2");
 nEndYear = v1.intVal + v2.intVal;

When I debug this code I notice v1 equal 14.000 VT_R8 and v2 equal 32.000 VT_R8
but when add v1 to v2 the nEndYear become 0.

Avatar of elcapitan
elcapitan

You have to add v1.dblVal+v2.dblVal

--EC--
Or you can use _variant_t double extractor:
Double v3 = (double)v1 + (double)v2;

--EC--
Avatar of MohdAsalah

ASKER

But how can I know if the variant value v1 and v2 have a double value not integral value????
ASKER CERTIFIED SOLUTION
Avatar of elcapitan
elcapitan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
? When using _variant_t you can use extractors (like double
>(), long() etc.) To extracts raw data from

so, your the code you have would work if you wrote it like this:

nEndYear = static_cast<long>(v1) + static_cast<long>(v2);