Click to See Complete Forum and Search --> : Converting CString to type VARIANT


Prasutagus
April 26th, 1999, 10:42 PM
I'm transferring a number of values from an Array to an OLE grid control (XGrid). The OLE object requires the value to be passed as typr VARIANT which I initialized as follows :

// Initialize Variables
int row, col;
tagVARIANT CellValue;
::VariantInit(&CellValue);



A Number of loops loads each column based on a user selection. Each column is either of type CString or int but they all need to be converted to type VARIANT which works ok for type int

// Load Skill Ability->Skill
col = 3;
for(row=2;row<SKILL_COUNT;row++)
{
CellValue.intVal = GetDocument()->m_Skills.GetSkillAbilitySkill(row-1);
m_XGrid4.TargetCell(row, col);
m_XGrid4.SetValue(CellValue);
}



For my CString columns I get the following message : <'binary '=' : no operator defined which takes a right-hand operand of type 'class CString' (or there is no acceptable conversion)>. I tried a number of types for VARIANT including bstrVal, cVal etc.

Thank you for you suggestions.

Pras

chiuyan
April 26th, 1999, 10:53 PM
I am not sure I follow exactly what you are doing there, but I would suggest that you use a COleVariant class. It can automatically convert from many different data types.

--michael

Bob Clarke
April 26th, 1999, 11:42 PM
Here's one option:

// str is a CString
COleVariant var(str.GetBuffer(), VT_BSTRT);
VARIANT var2 = var.Detach();
// now pass var2 to your function needing a VARIANT

Prasutagus
April 26th, 1999, 11:45 PM
Thank you - works well :-)

Pras