Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBScript Array Expansion Library

 
Logged in as: Guest
arrSession:exec spGetSession 2,17,41454
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
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!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 VBScript Array Expansion Library - 12/27/2006 12:55:29 AM  1 votes
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
This component is no longer available. Take a look at this topic instead: http://www.visualbasicscript.com/fb.aspx?m=59109

< Message edited by TNO -- 4/14/2008 8:13:46 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...
 
 
Revisions: 9 | Post #: 1
 
 RE: VBScript Array Expansion Library - 12/27/2006 3:15:00 PM   
  DiGiTAL.SkReAM


Posts: 1101
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
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

(in reply to TNO)
 
 
Post #: 2
 
 RE: VBScript Array Expansion Library - 12/29/2006 1:45:14 AM   
  ginolard


Posts: 1012
Score: 21
Joined: 8/10/2005
Status: offline
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 >


_____________________________

Author of ManagePC - http://managepc.net
AD Query Template - http://www.visualbasicscript.com/m_40609/tm.htm
Consolidated Scripting Framework - http://www.visualbasicscript.com/m_59109/tm.htm

(in reply to DiGiTAL.SkReAM)
 
 
Revisions: 2 | Post #: 3
 
 RE: VBScript Array Expansion Library - 12/29/2006 4:41:14 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline

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.

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ginolard)
 
 
Post #: 4
 
 RE: VBScript Array Expansion Library - 12/29/2006 6:33:04 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
*Documentation updated to include steps on Remote Scripting*

No need to assume .NET is installed

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 5
 
 RE: VBScript Array Expansion Library - 12/30/2006 2:55:57 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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.


Useful? Timesaving? or Pointless?

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 6
 
 RE: VBScript Array Expansion Library - 1/10/2007 12:53:10 PM   
  mrmore

 

Posts: 5
Score: 0
Joined: 11/9/2006
Status: offline
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

(in reply to TNO)
 
 
Post #: 7
 
 RE: VBScript Array Expansion Library - 1/10/2007 8:46:17 PM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
These look like good Ideas as well. I'll seriously consider them in an updated version when time permits.

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to mrmore)
 
 
Post #: 8
 
 RE: VBScript Array Expansion Library - 1/14/2007 7:04:17 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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:

JS.Concat(Array1,Array2,Array3.......Arrayn)
JS.Undupe myArray



_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 9
 
 RE: VBScript Array Expansion Library - 1/15/2007 8:41:12 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Version 2 is now uploaded, heres whats new:

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.





< Message edited by TNO -- 1/15/2007 8:44:22 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Revisions: 1 | Post #: 10
 
 RE: VBScript Array Expansion Library - 1/15/2007 10:57:39 PM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Documentation updated

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 11
 
 RE: VBScript Array Expansion Library - 1/16/2007 2:02:37 AM   
  dm_4ever


Posts: 2220
Score: 32
Joined: 6/29/2006
From: Orange County, California
Status: offline
Awesome , I can't believe you finished already. Can't wait to give it a try.

< Message edited by dm_4ever -- 1/16/2007 2:07:04 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to TNO)
 
 
Revisions: 1 | Post #: 12
 
 RE: VBScript Array Expansion Library - 1/16/2007 4:41:02 AM   
  DiGiTAL.SkReAM


Posts: 1101
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
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

(in reply to dm_4ever)
 
 
Post #: 13
 
 RE: VBScript Array Expansion Library - 1/16/2007 7:07:50 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
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.

Thanks for the question

< Message edited by TNO -- 1/16/2007 7:12:15 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 14
 
 RE: VBScript Array Expansion Library - 1/17/2007 12:32:42 AM   
  DiGiTAL.SkReAM


Posts: 1101
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
quote:

ORIGINAL: TNO

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

(in reply to TNO)
 
 
Post #: 15
 
 RE: VBScript Array Expansion Library - 1/17/2007 2:55:55 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I don't believe that the script engine starts another instance of itself. I know that it does not start another process at least.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 16
 
 RE: VBScript Array Expansion Library - 1/17/2007 5:10:43 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
quote:

I don't believe that the script engine starts another instance of itself.


My bad, what i meant was another instance of the WshScriptExec object.

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ebgreen)
 
 
Post #: 17
 
 RE: VBScript Array Expansion Library - 1/24/2007 5:20:36 PM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
I've moved the guide to my website so its easier for me maintain and easier to read.


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 18
 
 RE: VBScript Array Expansion Library - 2/6/2007 3:00:48 AM   
  DiGiTAL.SkReAM


Posts: 1101
Score: 6
Joined: 9/6/2005
From: Florida, USA
Status: offline
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

(in reply to TNO)
 
 
Post #: 19