Solved

How to access the data in an array of variant

Posted on 1997-08-25
3
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1304932
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
ID: 1304933
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
ID: 1304934
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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