Solved

How to access the data in an array of variant

Posted on 1997-08-25
3
323 Views
Last Modified: 2013-11-20
  I am programming an OCX which is to be used in IE. This ActiveX is used for drawing graph.So I require
the address of the array to be passed to it. I used safearray at first,
it works in Visual Basic and VC++ 5. But in IE using VBscript I cannot specify the data type of the array.And so my ActiveX received an array
of variants. So I have diffculty reading the data.

        In VB: I pass an array of doubles to my ocx.
        In VBscript : I pass an array of variant to it.

So how do I read the data from the array of variant.( since I read nothing from the safearray )

Here is part of my ocx code:

BOOL CEGraphCtrl::PlotGraph(const VARIANT FAR& xxArray, const VARIANT
FAR& yyArray)
{
        VERIFY(SafeArrayAccessData(yyArray.parray,(void HUGEP* FAR*)&yy ) ==
S_OK);
        VERIFY(SafeArrayAccessData(xxArray.parray,(void HUGEP* FAR*)&xx ) ==
S_OK);
               

if(yyArray.parray->rgsabound[0].cElements!=xxArray.parray->rgsabound[0].cElements)
        {
                MessageBox("Number of points in x-axis does not match number of points
in y-axis!");
                return FALSE;
        }
        numberofplot=1;
        xynum=xxArray.parray->rgsabound[0].cElements;
        InvalidateControl();


        return TRUE;
}


--
Siau Tan Long
stl@titan.np.ac.sg or stl@np.ac.sg
0
Comment
Question by:stl
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
Comment Utility
You can verify that the variant is an array by checking its "type":

  if (xxArray.vt & VT_ARRAY)
  {
    SAFEARRAY* sax = xxArray.parray;

    // Use SafeArrayGetDim() to check the dimensions
    // Use SafeArrayGetLBound(), SafeArrayGetUBound() to get the bounds
    // Use SafeArrayGetElement() to retrieve one variant
    // Once you have the variant, check to make sure it is a double or whatever type you need
  }


0
 

Author Comment

by:stl
Comment Utility
I had checked its "type".
The vt type is 400c (hex).
I use x.Format("%x",xxArray.vt) to find out about that.

According to the Visual C help, VT_BYREF=(int) 0x4000,
VT_ARRAY=(int) 0x2000, VT_VARIANT=12 which is c in hex.
That means I get a byref variant in the variant structure.
>> VARIANT   FAR* pvarVal;
Am I right to say so?

The program did not enter the if condition in this case:       
>>     if(xxArray.vt & VT_ARRAY )
>>     {...

So how do I access the data in pvarVal pointer?
(And please remember that I am using it in VBscript in IE,
script does not allow me to specify the data type of the array.)


0
 

Author Comment

by:stl
Comment Utility
BTW if I use my ocx in Visual Basic 5 :
I declare an array of variant and pass it to my ocx,
I get 200c for the vt type.
And the condition :
>>      if(xxArray.vt & VT_ARRAY )
will be entered.
and I can get the array.

But my ActiveX is to be used in browser not Visual Basic!
Can anyone help me?


0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now