Serving the Quantitative Finance Community

 
User avatar
SteveG
Topic Author
Posts: 0
Joined: September 26th, 2002, 2:43 pm

xlCoerce int to Str

October 17th, 2002, 2:05 pm

How do I convert an XLOPER from xltypeInt to xltypeStr? XLOPER xStr, xInt, xDestType; xInt.xltype = xltypeInt; xInt.val.num = xlParam->val.num; xDestType.xltype = xltypeInt; xDestType.val.w = xltypeStr; Excel4(xlCoerce, &xStr, 2, (LPXLOPER)&xInt, (LPXLOPER)&xDestType); Excel4(xlcAlert, 0, 1, (LPXLOPER)&xStr); Excel4(xlFree, 0, 1, (LPXLOPER)&xStr);ok I thought this would convert a number to a string, but it would appear that I am wrong again, any ideas on how I can achieve this?CheersSteve.
 
User avatar
Simplicio

xlCoerce int to Str

October 17th, 2002, 4:03 pm

I think;char* lpszTmp = NULL;int szLen = 0;XLOPER xDestType, xStr, xInt; xDestType.val.w = xltypeStr; xDestType.xltype = xltypeInt;Excel4(xlCoerce, (LPXLOPER)&xStr, 2, (LPXLOPER)&xInt, (LPXLOPER)&xDestType);if (xStr.xltype == xltypeStr){ szLen = (int) xStr.val.str[0]; if ( (lpszTmp = (char *) malloc(szLen+1)) != NULL) { strncpy(lpszTmp, &xStr.val.str[1],szLen); lpszTmp[szLen] = '\0'; }}is OK.
 
User avatar
SteveG
Topic Author
Posts: 0
Joined: September 26th, 2002, 2:43 pm

xlCoerce int to Str

October 18th, 2002, 7:52 am

Well i got it working in the end with thisExcel4(xlCoerce, &xStr, 2, xlParam, TempInt(xltypeStr));before I was being too clever, trying to copy the value out of a xloper into another one and then do the conversion, now I just do the conversion on the first one straight away. Also found out there is no need to create an xloper for the dest type, as the TempInt function returns an xloper, and all you need to do is specify which take you want it converted to.Hope this helps anyone in the future.Steve.