All Forums >> [Scripting] >> Windows Script Components >> VBScript Array Expansion Library Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
If you are still having difficulty getting the .WSC file to show a 'Register' command on Right-Click, a short-cut would be to paste the following text into a .REG file and import it into your registry. AFTER making a backup, of course. NOBODY should ever modify their registry without amking a full backup of their system, and being ready to perform a bare-metal restore on their computer. If you decide to utilize this reg file, I can not be held responsible for any damage it may do to your computer, your grades, your weight, your relationship with your parents/spouse/significant other/etc. or anything else bad that may happen. If, however, you win the lottery immediately after using this, I do accept cash and gold bullion.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
Not that I wish to rain on TNO's parade as he's put in so much work on this but here's how to use the ArrayList to do much of what TNO's extension does. It can't do everything that JS.Array can do (like Swap, Random, Shuffle) but it can do most of it.
Concat equivalent
Index equivalent
Del/Shift/Pop equivalents
LastIndexOf equivalent
Length equivalent
Sort & Reverse equivalents
Slice equivalent
< Message edited by ginolard -- 12/29/2006 1:47:16 AM >
Its no problem at all. Its true, the .NET components are another way to accomplish the same task, and the dll in fact has even more functionality that expands far beyond what I ever intended for this library. The primary goal of this project was to expand functionality without using any technology outside of the Windows Scripting Host itself. Plus I think this is a good example and introduction to the use of Script Components.
I know, I know, kind of soon for a version 2, but I couldn't resist. Heres what I'm considering as additions:
1-Dictionary - Exact same as in the WSH Notation, including its methods 2-Every() - runs a function on every item in the array and returns true if the function returns true for every item. 3-Filter() - runs a function on every item in the array and returns an array of all items for which the function returns true. 4-Walk() - runs a function on every item in the array. 5-Map() - runs a function on every item in the array and returns the results in an array. 6-Sum() - Adds all the items in the array and returns the result.
Sick! Looks as though a lot of time and effort has been put into this.
Here are some functions I wrote and use a lot. If they aren't worthy of inclusion in future versions, then maybe they'll help with some new ideas for features.
My code could probably be improved a little, but it works fine for me
Compare two arrays are store all matching items into new array
Compare array1 to array2 and store all items which do not match into new array
Merge two arrays and then remove all duplicate entries. Returns results in a dictionary object.
Hopefully, at the very least someone else will find these functions useful
Alright, version 2 is in progress, this is what I'm working on:
Every() - runs a function on every item in the array and returns true if the function returns true for every item.
Filter() - runs a function on every item in the array and returns an array of all items for which the function returns true.
Walk() - runs a function on every item in the array, altering original array.
Map() - runs a function on every item in the array and returns the results in an array.
Sum() - Adds all the items in the array and returns the result
Compare() - Compare two arrays 0-return true or false 1-return matches in new array 2-return failed matches in new array
IntArray() - This function allows you to quickly transform a string into an array of ints, much like an char array in C or similar languages. The method returns the int array, and does not transform the original string.
IntArray2String() - The purpose of this function, is to work together with the IntArray() function.and let a developer quickly transform a String into first an int array, and then back into a String. The method works on the array it's called on, and returns a new string, the array being worked on doesn't change. The array must further be all natural numbers (0 and up).
Dictionary - Just like the WSH, except it won't use this name when its done, it will inherently be available so you only have to do this once:
Dim JS Set JS= CreateObject("JS.Array")
Then from here you can use everything in the "Dictionary" without any extra effort:
JS.Push myArray,1 JS.Pop myArray JS.Del myArray,2
JS.Add("a","test") JS.Exists("a") etc...
Any input before version 2 is done?
P.S: mrmore: I used the basic ideas from your 3 functions and put the first two into a single function with an option parameter. The MergeArrays() function I didn't use because that functionality is already in the library:
The Dictionary is now built in and automatically available. This was entirely recreated with a JScript 2 dimensional array so there is no reliance on the ActiveX. This should be much faster than the ActiveX control and more reliable since the items are actually placed in the Dictionary in the order you add them.
Syntax for the "Dictionary" object: (These do exactly the same thing as the WSH documentation) JS.Add key,val JS.Count JS.Exists(key) JS.Item(key,newItem) JS.Items() JS.Key(key,newKey) JS.Keys() JS.Remove key JS.RemoveAll New Functions:
IntArray(str) ' transform a string into an array of ints (The Unicode of the string characters) IntArray2String(Array1) 'Turn the IntArray back into a string Sum(Array1) 'Return the Sum of the values in the array. Compare(Array1,Array2,Flag) 'Compare two arrays Flags: 0-Return True or False for wether the arrays match 1-Return the matches in a new Array 2-Returnthe unmatched in a new Array I decided not to include the following functions since I think they were excessive and 99% unecessary to anyone who would use this:
Every() - runs a function on every item in the array and returns true if the function returns true for every item. Filter() - runs a function on every item in the array and returns an array of all items for which the function returns true. Walk() - runs a function on every item in the array, altering original array. Map() - runs a function on every item in the array and returns the results in an array. LFold() - A function present in SML language: a recursive function that iterates through an array into a nested Function: F(1,F(2,F(3,F(4,F(5))))) RFol() - Same as above but reversed: F(F(F(F(F(5),4),3),2),1)
LFold and RFold look pretty psychotic and pointless, but in SML (a completely function based language) it 's supposedly really useful. Occams Razor won out on this one.
I'll update the Documentation when I get a free chance.
TNO, A question if I could. Would it be faster/more efficient to run a
rather than the sum function in your wsc? I hate to ask dumb questions like this, but I have tried to read the js that you wrote it in, and it makes no sense to me. So, was hoping that you could help out with this one. Guess I'm just js-deficient. heh heh
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
Actually it would be exponentially slower, and heres why:
The Execute Statement in vbscript and the Eval() method in JScript both do generally the same thing "Take whatever is in this string and run it as code". Now, to do that, the scripting engine has to start another instance of itself to evaluate your code and then execute it whatever is inside it. This by itself would make it more efficient to just execute the code normally.
'Get the vbscript array and pass it to JScript for the answer
//Convert the vbscript Array into a JScript hashtable (makes it extremely speed efficient.) //go thorugh array one by one and add to sum. Return the sum back into vbscript
So my final answer on this subject in general is this: With small arrays (1,000 elements or less), its probably a little bit faster to let vbscript to do the work. When the arrays get significant in size (100,000+ elements in the array), JScript is the prime choice. If your projects require a faster result, let me know and I can optimize this and maybe get 4 times the speed. Functionality was my #1 concern, efficiency 2nd.
Actually it would be exponentially slower, and heres why:
The Execute Statement in vbscript and the Eval() method in JScript both do generally the same thing "Take whatever is in this string and run it as code". Now, to do that, the scripting engine has to start another instance of itself to evaluate your code and then execute it whatever is inside it. This by itself would make it more efficient to just execute the code normally.
Could you elaborate on that? From everything that I have seen, the execute command doesn't work that way.
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury
Ok, am I doing something wrong here? I am trying to register this WSC via script, and am unable to do so. When i use the command: regsvr32 scrobj.dll /n /i:file:\\%windir%\system32\JSArray-v2.wsc it creates errors, justintime debugger windows popup, etc. BUT, i can then go into my script and run a createobject("JS.Array") with no errors. And the JS.Array object works.
But, the windows popping up are causing problems when I want to do this silently, etc. I've also tried using teh /s parameter, but that doesn't help - i still get popups. is there something else that I am missing?
_____________________________
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy." -Master Wong, from Balls of Fury