From JScript Arrays To VB Arrays
HomeJScriptJXtension
Main Menu Home HTA JavaScript PHP Examples Million Digit Number Free Samples Disable Excel Menus Display Random Facts Drive Information Emulate Lock Keys Enable Excel Menus Hoax Virus Message Includables jPaq Modified Alert Box toVBArray() Outer Links MSDN Reference JScript Reference

Purpose

While working writing JScript code to interact with COM objects, it may be necessary to pass an array of strings or other data types.  Unfortunately, due to the design of the method, JavaScript or JScript arrays may not be accepted.  Therefore it is necessary to find an easy way to convert a JavaScript array into a VBArray.

Code

You may download or use the following code in your JScript to provide a function to translate a JScript array into a VBArray:

// Returns the array as a VBArray.
Array.prototype.toVBArray = function()
{
	var dict = new ActiveXObject("Scripting.Dictionary");
	for(var i = 0, len = this.length; i < len; i++)
		dict.add(i, this[i]);
	return dict.Items();
};

The following example will show you how to use the method defined above:

/*
.
.
.
*/
// Create the PivotTable.
var pt = wb.PivotCaches().Add(/*SourceType:=*/xlDatabase,
	/*SourceData:=*/ws.UsedRange)
		.CreatePivotTable(/*TableDestination:=*/wsPT.Range("A3"));
pt.MergeLabels = true;
pt.AddFields(["Manufacturer", "Cost Center"].toVBArray());
/*
.
.
.
*/

Related Search Results

  1. Wormbites 2006:
    The ultimate Snake game with multiple brain-teasing levels. You can also custom design you own levels.
  2. JScript - Modified Alert Box:
    Use the alert function in any stand-alone JScript.
  3. JavaScript - Dynamically Creating Tables:
    Gives an example of how to use JavaScript in conjunction with HTML and CSS to dynamically create tables.
  4. JavaScript - Why Use getAttribute(...) In JavaScript?:
    Learn why getAttribute is at times more useful that dot notation and bracketed notation.
  5. JavaScript Snippet - getAbsPathFor(...):
    Get the absolute path from a given relative path.