Solved

How to access the data in an array of variant

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

733 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