Solved

How to access the data in an array of variant

Posted on 1997-08-25
3
337 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 115
format the code in java 6 94
wait notify demo infinite loop 3 110
Window placement 17 83
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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