Excel through learning

Excel through learning
Your source of knowledge

Tuesday, August 12, 2008

Create Array of record in Agilent VEE

Record in VEE is just like Structure in C or C++. It allows user to group different data type together as fields. There are 2 ways to create Record type:





  • Record Constant container, refer Figure 1

  • Build Record container

I usually prefer to create a UserFunction to generate application specific Record type. Figure 1 shows a sample Record creation UserFunction I created.




Figure 1: "New Record" UserFunction


The reason I create function like this are:



  • With this function, I'm able to generate the record variable in formula box, then I start store my value to the fields directly.

  • In case I decide to change the Record's fields, I just need to update the UserFunction instead of updating each Record constant container.

Sometimes I need ot create an Array of Record. One of the benefits to use the Record Array is array allows us to perform sorting. We can use the Sort(Array,dirction, Sort field) built in function. There are basically 2 ways to create a Record Array:



  • User the Concat(x,y) built in function

  • Use the Build Record container, Output Shape set to "Array 1D". Refer to Figure 2.



Figure 2: Creating Record Array with Build Record container


The first method only allows us to concatenate 2 array at one time. If we have 10 elements, that means we have to call the function 10-1 = 9 times (Concat(R10,Concat (R9,R8))...). While Build Record container allow us to build the array with the container itself, it is not generic. That means, for different Record type, we will use the Build Record container. Refer to Figure 2 for detail of creating a Record Array.


I was thinking to create a generic UserFunction which allow me to create an Array for any record type. Again, I used similar approach as my previous post, Reversing Array in Agilent VEE, using dynamic Formula evaluation method. Figure 3 shows the Array UserFunction.




Figure 3: Array UserFunction


I do have worry on this type of approach actually, that is when the Formular text grow too large. Or in this Array UserFunction's case, when we want to create a large array, let say 10000 elements, this means that the "Formula" input parameter has to be a very long text. Evaluating such a large text sure have performance drawback.


So, I did a simple comparison between the Array UserFunction method and also the Build Array method. For the Build Array method, from the results in Figure 2, it takes 45.13mS to create a 10000 elements array. For Array UserFunction, to create an array with similar size and data, it needs 2.392 S. Refer to figure 4. From the results, it shows that the Array UserFunction is about 53 time slower than the Build Array method.



Figure 4: Creating Array using "Array" function.


Lesson Learnt:
If you have concern with the performance or your application need to create Record Array many times, then you probably wants to consider the Build Array method. If the array size is not large, then you may use the Array UserFunction to simplify the code. Comparing Figure 2 and Figure 4, it is clear the Array UserFunction code is more simpler.


Download the sample code here


reference: Reversing Array in Agilent VEE,

0 comments: