[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How to access the data in an array of variant

Posted on 1997-08-25
3
Medium Priority
?
361 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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

656 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