Page 1 of 1

xlCoerce int to Str

Posted: October 17th, 2002, 2:05 pm
by SteveG
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.

xlCoerce int to Str

Posted: October 17th, 2002, 4:03 pm
by Simplicio
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.

xlCoerce int to Str

Posted: October 18th, 2002, 7:52 am
by SteveG
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.