Hi,
I need to take an input of 1D array, each item pipe delimited, and make a 2D array for column sorting.. Can anyone please help as my first ady with jscript, and haven't a clue why i get this error; I thought I was using other scripts exactly?!...
Any idea why?; or is there a better way anyway (in ScriptObject, I can't seem to pass 2D arrays... so need to pass 1D.)best, Randall
I need to take an input of 1D array, each item pipe delimited, and make a 2D array for column sorting.. Can anyone please help as my first ady with jscript, and haven't a clue why i get this error; I thought I was using other scripts exactly?!...
Code:
var list = [
"1|359|No a Test xxxxxxxxxxxxxxx|0|08/18/2003|Approved",
"2|268|test character fields for 500|129|07/14/2003|Approved",
"3|288|textarea filled XXXXXXXx|0|07/15/2003|Approved"];
WScript.Echo(list.join("\n"));
WScript.Echo(list[0]);
//~ myarray.sort(mysortfn);
ListSorted=SortArray(list);
WScript.Echo(ListSorted.join("\n"));
//~ ;==========================================
//~ ;==========================================
function SortArray(arrArray) {
WScript.Echo(arrArray[0]);
var tempArray = arrArray[0].split('|');
WScript.Echo(tempArray[0]);
var NewArray = new Array();
//~ var square = new Array();
var count;
for (count = 0; count < tempArray.length; count++) ;{
NewArray[count] = new Array(); // This declares each column in turn
}
//~ var NewArray[arrArray.length][tempArray.length];
for (var i = 0; i < arrArray.length; i++) {
var tempArray = arrArray[i].split('|');
WScript.Echo(tempArray[0]);
for (var j = 0; j < tempArray.length; j++) {
NewArray[i][j]=tempArray[j]++;
}
}
WScript.Echo(NewArray.join("\n"));
//~ ;==========================================
NewArray.sort(value);
return NewArray;
//~ return arrArray[2][1];
}
function value(a,b) {
a = a[1]+a[2];
b = b[1]+b[2];
return a == b ? 0 : (a < b ? -1 : 1);
}
>cscript /nologo sortvbsjs.js
1|359|No a Test xxxxxxxxxxxxxxx |0|08/18/2003|Approved
2|268|test character fields for 500|129|07/14/2003|Approved
3|288|textarea filled XXXXXXXx|0|07/15/2003|Approved
1|359|No a Test xxxxxxxxxxxxxxx |0|08/18/2003|Approved
1|359|No a Test xxxxxxxxxxxxxxx |0|08/18/2003|Approved
1
1
C:\Programs\Sea rchEngine\sortv bsjs.js(29, 4) Microsoft JScript runtime error: Object expected
1|359|No a Test xxxxxxxxxxxxxxx |0|08/18/2003|Approved
2|268|test character fields for 500|129|07/14/2003|Approved
3|288|textarea filled XXXXXXXx|0|07/15/2003|Approved
1|359|No a Test xxxxxxxxxxxxxxx |0|08/18/2003|Approved
1|359|No a Test xxxxxxxxxxxxxxx |0|08/18/2003|Approved
1
1
C:\Programs\Sea rchEngine\sortv bsjs.js(29, 4) Microsoft JScript runtime error: Object expected
Comment