DataRange::SetToVirtualDataset

Description

It sets a DataRange object into a virtual dataset.

Syntax

BOOL SetToVirtualDataset(LPCSTR lpcszVSName)

Parameters

lpcszVSName
[input]

Return

True if Successful

Examples

// This method is used by the following OC code to fix all the virtual matrices in the corrupted project
static     BOOL       _fix_virt_series(LPCSTR lpcszVirtSeries, Worksheet &wks,
                                                                int nRowXValues,
                                                                int nColumnYValues,
                                                                int nR1,
                                                                int nR2,
                                                                int nC1,
                                                                int nC2
                                                                )
{
        DataRange       rng;
        //int                     nn = rng.Add("X", wks, int nR1, int nC1, int nR2, int nC2);
        int                        nn = rng.Add("X", wks, nRowXValues, nC1, nRowXValues, nC2);
        nn = rng.Add("Y", wks, nR1, nColumnYValues, nR2, nColumnYValues);
        nn = rng.Add("Z", wks, nR1, nC1, nR2, nC2);

        BOOL               bb = rng.SetToVirtualDataset(lpcszVirtSeries);
        ASSERT( bb );
        
        return bb;
}

static     BOOL       _fix_virt_matrix_ORG_17473(LPCSTR lpcszVirtSeries, Worksheet &wks)
{
        int                nRowXValues = 0;              // the first row of data always contains the X-values
        int                nColumnYValues = 0;           // the first column always contains the Y-values
        int                nR1 = 1;
        int                nR2 = wks.GetNumRows() - 1;
        int                nC1 = 1;
        int                nC2 = wks.GetNumCols() - 1;
        
        return _fix_virt_series(lpcszVirtSeries, wks, nRowXValues, nColumnYValues, nR1, nR2, nC1, nC2);
}


static     BOOL       _fix_virt_matrix_ORG_17473(const string &strVMname, int index)
{
        // Get the long name:
        MatrixObject mo( strVMname ); 
        if(!mo)
        {
                ASSERT(0);
                return FALSE;
        }
        
        string          strVMLongName = mo.GetLongName();
        if ( strVMLongName.IsEmpty() )
        {
                ASSERT(0);
                return FALSE;
        }
        
        // Assume that the VM's long name matches the sheet name of the source worksheet
        // for this virtual matrix 
        // Need to find the worksheet:
        foreach(WorksheetPage wp in Project.WorksheetPages)
        {
                foreach(Layer lay in wp.Layers)
                {
                        Worksheet       wksh = lay;
                        string          strName = wksh.GetName();
                        if ( 0 == strName.CompareNoCase(strVMLongName) )
                        {
                                string          strDump;
                                strDump.Format("index = %d,\t VM Name: %s,\t Workbook: %s,\t Sheet: %s", index, strVMname, wp.GetName(), wksh.GetName());
                                out_str(strDump);
                                _fix_virt_matrix_ORG_17473(strVMname, wksh);
                                return TRUE;
                        }
                }
        }
        
        return TRUE;
}

// For fixing virtual matrices in the corrupted project
void       fix_virt_matrices()
{
        // Get all the virtual matrices:
        QueryResult qr;
        qr.Build("Select VIRTUALMATRIX from Project");
        vector<string>  vsVMListNames;
        qr.GetNames(vsVMListNames, QUERYRESULTNAME_SNAME);
        
        for (int ii =0; ii < vsVMListNames.GetSize(); ii++)
        {
                _fix_virt_matrix(vsVMListNames[ii], ii);
        }
        
}

Remark

See Also

header to Include

origin.h