CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    29

    Converting CString to type VARIANT

    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


  2. #2
    Join Date
    May 1999
    Location
    Seattle, WA USA
    Posts
    423

    Re: Converting CString to type VARIANT

    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


  3. #3
    Join Date
    May 1999
    Posts
    42

    Re: Converting CString to type VARIANT

    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


  4. #4
    Join Date
    Apr 1999
    Posts
    29

    Re: Converting CString to type VARIANT

    Thank you - works well :-)

    Pras


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured