Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Array Expansion

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array Expansion
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2 3 4   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Array Expansion - 12/18/2006 9:50:53 PM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
This Component is currently under a large rewrite and is unavailable at this time. When complete I'll bump this thread. (I'm working to combine array functions with a large amount of other functions into a single component so stay tuned)

As you may or may not have known, vbscript is stuck at version 5.6 with no plan by Microsoft for an update. With VB.NET, Powershell, and JScript 8.0 (and JS.NET), they aren't too concerned to updating this language any time soon. So that leaves us with what? A stagnant language......

All is not lost though since the great minds at Microsoft had to foresight give us the ability to expand the language ourselves and create what we wanted/needed in an ever changing digital environment. So with that in mind, I'd like to embark on a new project to combine/expand the Array() & Dictionary Object with your help if you will offer it.

The first step is defining what we have and do not have, and what we'd like to have.

VBScript Array()
LBound()
UBound()
ReDim
Redim Preserve
Filter() <---kinda related
IsArray()
Join()
Split()

VBArray Object
dimensions()
getItem()
lbound()
ubound()
toArray()

Scripting.Dictionary Object
Add()
Exists()
Items()
Keys()
Remove()
RemoveAll()
Count
Item
Key

What I think we need:
length   (How big is the array?)
inArray()   (http://www.visualbasicscript.com/m_41079/mpage_1/key_sort/tm.htm#41161)
concat() (join 2 or more arrays into one)
pop() (Removes the last element from an array and returns it)
push() (add elements to the end of an array)
reverse() (reverse the order of an array)
shift() (Removes the first element of an array and return it)
slice() (returns a smaller array from a larger array)
sort() (sort the array)
splice() (delete or replace part of an array with another array)
unshift() (inserts new elements at the beginning of an array)
A better Associative array than Dictionary:
treat each entry as object.property
and
treat each entry as object[property]



Additions, opinions, comments, insults,or  suggestions?

< Message edited by TNO -- 4/11/2008 4:52:55 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...
 
 
Post #: 1
 
 RE: Array Expansion - 12/18/2006 11:46:53 PM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
are you talking about just creating classes to add this functionality?

or modifying WSH?

personally, I'm somewhat divided on this, with the up and coming upgrades, why bother?

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to TNO)
 
 
Post #: 2
 
 RE: Array Expansion - 12/19/2006 12:03:58 AM   
  TNO


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

are you talking about just creating classes to add this functionality?


I'm talking about Script Component files that act as COM objects:

MyObject=CreateObject("JavaScript.Array")


from that point treat it like an extended Dictionary Object

quote:

with the up and coming upgrades, why bother?


What upgrades you referring to?

< Message edited by TNO -- 12/19/2006 12:12:39 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to kirrilian)
 
 
Post #: 3
 
 RE: Array Expansion - 12/19/2006 12:19:17 AM   
  ehvbs

 

Posts: 2037
Score: 48
Joined: 6/22/2005
From: Germany
Status: offline
Hi TNO,

  Set MyObject=CreateObject("JavaScript.Array")

perhaps I'd have refrained from being "old pedantic" again; but I have a
(serious) question anyway. Is this JavaScript available just now (curtesy
of MS) or is it part of your plan (a - maybe not so thin - wrapper around
the JScript datastructure)?

(in reply to TNO)
 
 
Post #: 4
 
 RE: Array Expansion - 12/19/2006 12:27:06 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Set MyObject=CreateObject("JavaScript.Array")

This is entirely semantic, and could just as easily be:

Set MyObject=CreateObject("Bill.Clinton")

This name comes from here (the wsc file)

quote:

    <?XML version="1.0"?>
  <package>
    <component id="component1">
       <registration progid="JavaScript.Array"/>
       <public>
          <method name="blah">
              <parameter name=blah/>
              <parameter name="blah"/>
           </method>
       </public>
       <script language="JScript or vbscript or PerlScript, etc">
          <![CDATA[
          ....
          ]]>
          </script>
    </component>
  </package>


So yes, this is a wrapper. (Alot of people said thir workplaces don't allow anything but vbs, so I figured dumping all the functionality in a COM object would be smartest)

< Message edited by TNO -- 12/19/2006 12:30:03 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Array Expansion - 12/19/2006 12:55:38 AM   
  ginolard


Posts: 1014
Score: 21
Joined: 8/10/2005
Status: offline
Interesting idea.  Ok, well, just throw something else into the mix.

Shuffle() - Randomize the contents of an array

What?  What do you mean why would I want to do that? 

_____________________________

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 TNO)
 
 
Post #: 6
 
 RE: Array Expansion - 12/19/2006 1:54:39 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
I can't believe I forgot about shuffle() 

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ginolard)
 
 
Post #: 7
 
 RE: Array Expansion - 12/19/2006 2:16:38 AM   
  ginolard


Posts: 1014
Score: 21
Joined: 8/10/2005
Status: offline
Switch(x,y) - Swap the position of two array elements

Ooh, ooh, I know.  Be able to Redim Preserve more than the last element of a multi-dimensional array.

_____________________________

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 TNO)
 
 
Post #: 8
 
 RE: Array Expansion - 12/19/2006 2:41:58 AM   
  TNO


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

Be able to Redim Preserve more than the last element of a multi-dimensional array.


You gonna have to explain this one to me....

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ginolard)
 
 
Post #: 9
 
 RE: Array Expansion - 12/19/2006 3:00:37 AM   
  ginolard


Posts: 1014
Score: 21
Joined: 8/10/2005
Status: offline
Ahem.  By element I meant, of course, dimension

_____________________________

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 TNO)
 
 
Post #: 10
 
 RE: Array Expansion - 12/19/2006 5:20:46 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
quote:

ORIGINAL: TNO

quote:

are you talking about just creating classes to add this functionality?


I'm talking about Script Component files that act as COM objects:

MyObject=CreateObject("JavaScript.Array")


from that point treat it like an extended Dictionary Object

quote:

with the up and coming upgrades, why bother?


What upgrades you referring to?


Ah ok, I understand now.

By upgrades I am referring to the reasons you gave why WSH hasn't been updated of course

I think this is an interesting idea and would be interested in helping.

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to TNO)
 
 
Post #: 11
 
 RE: Array Expansion - 12/19/2006 5:42:09 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Well, In about an hour or less I'll have a beta completed. I'll need some examples of the funcions being used for something, since I've got no idea what you all have in mind, lol. (I'm also going to post it here before its been fully tested since I think that will bring the bugs to the light faster) 

< Message edited by TNO -- 12/19/2006 7:00:41 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to kirrilian)
 
 
Post #: 12
 
 RE: Array Expansion - 12/19/2006 6:56:43 AM   
  TNO


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


Mission Accomplished: Heres the Beta version (any bugs or other additions you can think of?)

Installation:

1. Download Here: http:www.thenewobjective.com/website/development/JavaScript/Components/vbsArrays/JSArray-v1.wsc
2. Save to anywhere on your computer
3. Right Click on the file and select Register

Getting started:

Its as simple as this:

Dim Foo
Set Foo = CreateObject("JS.Array")


How to Use:

Foo.Concat(Array1,Array2)
Combine two arrays into one.

Foo.Index(Array, Value, Begin, Strict)
Returns the position in the Array of the FIRST element that matches the specified Value.
If the argument is not found in array, a value of -1 is returned.
Array-The Array being searched
Value-What you are looking for in the Array
Begin-Where to start looking in the Array
Strict-This can be either 0 or 1
   0-
Match the value only
   1-Match value and type
   Explanation- Within an array, elements can be of different types.For Example 4 is a number, '4' is a string, and [4] is an array itself. You may want to know the difference

Foo.Insert(Array,Index,Value)
Insert Value at Index in the Array, without overwriting the existing keys. This returns the new array

Foo.LastIndex(
Array, Value, Begin, Strict)
Returns the position in the Array of the LAST element that matches the specified Value.
If the argument is not found in array, a value of -1 is returned.
Array-The Array being searched
Value-What you are looking for in the Array
Begin-Where to start looking in the Array
Strict-This can be either 0 or 1
      0-
Match the value only
      1-Match value and type
      Explanation- Within an array, elements can be of different types.For Example 4 is a number, '4' is a string, and [4] is an array itself. You may want to know the difference


Foo.Length(Array)
Returns the length of an Array.Note: The elements in the Array do not have to be contiguous, so this will not necessarily return the number of elements in the array. For example: If my array is (0,1,2,3,4,,,,5,,6,,7,,,,8,9) Then Length will return 18

Foo.Pop(Array)
Deletes the last element in the Array or returns undefined if array is empty.  This function returns the new array.

Foo.Push(Array,Item)
Adds an Item to the end of an Array. This function returns the new array.

Foo.Random(Array)
Returns a random element from the Array.

Foo.Reverse(Array)
Returns a new array with the elements reversed. Any empty elements in the array are filled with an undefined value

Foo.Shift(Array)
Deletes the first elementin the Array or returns undefined if array is empty.  This function returns the new array.

Foo.Shuffle(Array)
Randomly shuffles the Array's elements into new positions. This function returns the new array

Foo.Slice(Array,Start,End)
Returns an Array object containing the specified portion
The Slice function copies up to, but not including, the element indicated by End. If Start is negative, it is treated as the length of the Array + Start  If End is negative, it is treated as the length of the Array + End tinues to the end of arrayObj. If End occurs before Start, no elements are copied to the new array.


Foo.Sort(Array,Type)
Returns an Array sorted according to the type:
0-Dictionary Sort (This means that '30' is less than '4' and gets sorted that way. If your array consists entirely of numbers then you probably want to sort numerically instead.
)
1-Reverse Dictionary Sort
2-Ascending Numeric Sort
3-Descending Numeric Sort

Foo.Splice(Array1,Start,DeleteCount,Array2)
This function takes Array1 and deletes elements beginning at Start and so on specified by DeleteCount. Array2 is then inserted in the deleted position creating a new Array. For example:
Array1= ("A","B",C)
Array2=("X","Y","Z")

MyArray=Foo.Splice(Array1,1,1,Array2)
MyArray now equals ("A","X","Y","Z","C")

Foo.Split2(String,Separator)
Creates an array from a String using the Separator defined . Unlike the normal Split() function, Split2() will let you split the String using a regular expression or an empty string ""

Foo.Swap(Array,Index1,Index2)
Swap the position of Index1 and Index2 in Array

Foo.Undupe(Array)
Removes Duplicates from Array and returns the new array

Foo.UnShift(Array1,Element)
Adds Element to the begginning of Array1 and returns the new array

< Message edited by TNO -- 12/19/2006 7:20:00 AM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ginolard)
 
 
Post #: 13
 
 RE: Array Expansion - 12/19/2006 7:06:35 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
a few things:

1. WOW!! busy person lol
2. Your link isnt right...
3. I've never heard of these wsc files but from my quick research, they seem like a really easy way to extend the language, just like you proposed

i will give these a workout and let you know if i have any ideas/suggestions

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to TNO)
 
 
Post #: 14
 
 RE: Array Expansion - 12/19/2006 7:09:21 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
oops, 1 bug so far. I had an extra space at the beginning. fixed now

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 15
 
 RE: Array Expansion - 12/19/2006 7:25:20 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
just a quick glance through and everything looks good, i think it's funny that you are using jscript to extend vbscript btw

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to TNO)
 
 
Post #: 16
 
 RE: Array Expansion - 12/19/2006 7:25:37 AM   
  TNO


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

. Your link isnt right...


Hmm, thats a weird forum glitch. Its fixed now.


I'm bug testing the same time as everyone else so I'm expecting some hiccups 

I can't quite figure out how to create a proper Type Library yet. That would be a nice feature since you could view the script in your object browser, not to mention be able to use this oustide the WSH in languages like C++ or VB.NET and so on

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 17
 
 RE: Array Expansion - 12/19/2006 7:28:59 AM   
  TNO


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

i think it's funny that you are using jscript to extend vbscript btw


VBScript is a master when it comes to Dates. But for Arrays, JScript is the winner by far. (I had to create a pretty monstrous library to get JavaScript to do some of the same Date Function vbs has...) A give and take relationship I guess

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 18
 
 RE: Array Expansion - 12/19/2006 7:53:35 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
quote:

ORIGINAL: TNO

quote:

i think it's funny that you are using jscript to extend vbscript btw


VBScript is a master when it comes to Dates. But for Arrays, JScript is the winner by far. (I had to create a pretty monstrous library to get JavaScript to do some of the same Date Function vbs has...) A give and take relationship I guess


I couldnt agree with you more

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to TNO)
 
 
Post #: 19
 
 RE: Array Expansion - 12/19/2006 8:10:18 AM   
  TNO


Posts: 1040
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Minor bug with Concat() fixed.

a.toArray().concat(b).join('\b'); --->  a.toArray().concat(b.toArray()).join('\b');

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to kirrilian)
 
 
Post #: 20
 
 
Page:   [1] 2 3 4   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Array Expansion Page: [1] 2 3 4   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts