Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: 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 >> RE: Array Expansion
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 [3] 4   next >   >>
Login
Message << Older Topic   Newer Topic >>
 RE: Array Expansion - 12/21/2006 9:38:26 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Ok experts I need your opinion.

Would you prefer that a new Array be built with each function or the original Array altered?

For example:

myArray=Array(1,2,3,4,5)

JS.Push(myArray,6)


so that myArray now equals Array(1,2,3,4,5,6)

OR

myArray=Array(1,2,3,4,5)

myArray2=JS.Push(myArray,6)


so that myArray2 now equals Array(1,2,3,4,5,6)
and myArray now equals Array(1,2,3,4,5)?

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to TNO)
 
 
Post #: 41
 
 RE: Array Expansion - 12/21/2006 9:57:39 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
I may be greedy and too optimistic:

Why not do both following the pattern

fFunction fopX()
   dimvar tmpA
   sopX tmpA
   return tmpA
}

Sub sobX( ByRef aA )
   dothisandthatto aA
End Sub

systematically?

(in reply to TNO)
 
 
Post #: 42
 
 RE: Array Expansion - 12/21/2006 10:28:45 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Regarding the Insert problem: Sorry no solution, because I'm still working
on coming to grips with your code. But this test code (easily extended, I hope)
indicated to me that inserting at the head is one problem spot.


      

(had to append the first forgotten sample output)

< Message edited by ehvbs -- 12/21/2006 10:31:23 AM >

(in reply to ehvbs)
 
 
Post #: 43
 
 RE: Array Expansion - 12/21/2006 10:34:31 AM   
  dm_4ever


Posts: 2432
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
quote:

TNO
Would you prefer that a new Array be built with each function or the original Array altered?


I would go with the altered, but that's just me. Then again, I suppose as long as the arrays are returned in a consistent (whether a new array or altered) maner it would be best.

< Message edited by dm_4ever -- 12/22/2006 12:53:21 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)
 
 
Post #: 44
 
 RE: Array Expansion - 12/21/2006 9:16:32 PM   
  TNO


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


Insert() bug fixed

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to dm_4ever)
 
 
Post #: 45
 
 RE: Array Expansion - 12/22/2006 12:10:40 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Heres the status thus far:

<---Function is complete and passed all bug tests)
(<--Function is incomplete or bugged)


Concat(Array1,Array2,Array3.......Arrayn) (Returns a new array)
Index(Array1,Value,Begin,Strict) (Returns a value)
Del(Array1,Index) (Alters Original Array)
LastIndex(Array1,Value,Bottom Limit,Strict) (Returns a value)
Length(Array1) (Returns a value)
Pop(Array1) (Returns Last element value and alters original Array)
Push(Array1,Value) (Alters original Array and returns new length value)
Random(Array1) (Returns a value)
Reverse(Array1) (Alters Original Array)
Replace(Array1,Index,Value) (Alters Original Array)
Shift(Array1)  (Alters Original Array, returns a value)
Shuffle(Array1) (Alters Original Array)
Slice(Array1,StartI,EndI) (Returns a new Array)
Sort(Array,Type) (Alters Original Array)
Splice(Array1,Start,DelCount,Array2) (Alters Original Array)
Split2(String,Separator) (Returns a new array)
Swap(Array1,Index1,Index2) (Alters Original Array)
Undupe(Array1) (Alters Original Array)
UnShift(Array1,Value) (Alters Original Array)



< Message edited by TNO -- 12/23/2006 6:34:14 AM >


_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to TNO)
 
 
Post #: 46
 
 RE: Array Expansion - 12/22/2006 4:49:34 AM   
  dm_4ever


Posts: 2432
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Suggestion for the Shift. I'm not experienced with JScript, but figured this would be a good time to try a little.


      


UnShift

      

The following may not be the most efficient but it lets me add several values using UnShift with the same JScript code shown above


      

< Message edited by dm_4ever -- 12/22/2006 6:00:12 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)
 
 
Post #: 47
 
 RE: Array Expansion - 12/22/2006 4:54:08 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I admit that I haven't looked at the code, but I would like to advise caution regarding ever using Split() and Join(). I would go the potentially slower but safer route of rebuilding the array by hand.

_____________________________

"... 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 dm_4ever)
 
 
Post #: 48
 
 RE: Array Expansion - 12/22/2006 5:25:07 AM   
  dm_4ever


Posts: 2432
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
For the slice since the end is optional and I'm not sure how to make it so that we can leave that part empty I tried the following:


      

_____________________________

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)
 
 
Post #: 49
 
 RE: Array Expansion - 12/22/2006 6:00:27 AM   
  TNO


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

I admit that I haven't looked at the code, but I would like to advise caution regarding ever using Split() and Join(). I would go the potentially slower but safer route of rebuilding the array by hand.


Thanks for the advice, but I've worked with translating the code between the two languages enough to know the what pitfalls there are.

Passing the workload into JScript and sending the results back save alot of time and codespace. (JScript arrays aren't true arrays but hashtables).
because of this fact there is a little overhead that I don't like (myArray.toArray()) <--Turning a standard array into JScript's hashtable array. From this point the JScript speed demon does what it needs to do and turns the result into a string (a string separated by the BackSpace character) as weird as that sounds I figured it was the smartest method since the odds of having ASCII code 8 in your array is extremely unlikely at best. The string is then passed back into VBSscript to get split back into a True Array to be used by the rest of your program.

I do agree that its not always the best idea, and that sometimes its faster to just build a VBScript remake instead of translating back and forth, and in those cases (when you look at the code) you'll notice that a number of the functions are 100% vbs.



dm_4ever, thats an excellent start at JS, but as a hint for the future, you can save yourself alot of typing like this:

   function aShift(a) {
      a = a.toArray();
      a.shift();
      return a.join('\b')
  }


is the same as

function aShift(a){
  return a.toArray().shift().join('\b')
}



Takes a little to get used to I admit, but once the basic premise is there you can pick it up almost as easy as vbs

I'm going to play with it a bit more with all your suggestions, maybe even get lucky and get it all working in a couple hours.

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to dm_4ever)
 
 
Post #: 50
 
 RE: Array Expansion - 12/22/2006 6:23:21 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
It took me about 10 seconds to think of an instance where using SPlit() and Join() with Chr(8) would be a problem. If I want to put an undo feature into an HTA that works like your standard editor undo, then I woould need to essentially log keystrokes for an editable field. THe easiest way would be to just push them onto an array and pop them off for the undo. I backspace a lot when I type so I would need to have Chr(8)s in the array.

_____________________________

"... 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 TNO)
 
 
Post #: 51
 
 RE: Array Expansion - 12/22/2006 6:24:28 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I would like to point out that I am in no way attempting to denigrate the great work that you have done on this. Just looking for pitfalls.

_____________________________

"... 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 ebgreen)
 
 
Post #: 52
 
 RE: Array Expansion - 12/22/2006 6:31:21 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Good example. How about ASCII 7 (Bell)?

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 53
 
 RE: Array Expansion - 12/22/2006 6:32:51 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
It would work except for when you are shelling out to some app and cpturing the output to put into an array and the app beeps to get the user's attention.

_____________________________

"... 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 TNO)
 
 
Post #: 54
 
 RE: Array Expansion - 12/22/2006 6:43:10 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Alright then...what delimiter do you suggest we use as the 90% solution?

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 55
 
 RE: Array Expansion - 12/22/2006 6:46:52 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
I suspect the bell is your best bet. I'm just making the point that the best solution (from a data safe perspective) is to not use Split() and Join() at all.

_____________________________

"... 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 TNO)
 
 
Post #: 56
 
 RE: Array Expansion - 12/22/2006 7:18:05 AM   
  TNO


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

I would like to point out that I am in no way attempting to denigrate the great work that you have done on this. Just looking for pitfalls.


Its a group effort. this is exactly the kind of criticism I'm looking for. I've changed the delimiter to Bell, and uploaded the file.

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to ebgreen)
 
 
Post #: 57
 
 RE: Array Expansion - 12/23/2006 12:19:24 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Bah humbug.....Everything works now except Shift() and Unshift()

As you can see from the list above, alot of the functons now alter the original array to save you th time and overhead of declaring a new variable to hold the new array each time you change it.

For example:

Instead of doing this:

MyArray2=JS.Push(MyArray1,"Hola Bueno!!!")

Just do this:

JS.Push MyArray1, "Hola Mundo!!!

The original array is altered.

Another example:

JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray
JS.Shuffle MyArray
JS.Sort MyArray

The original array is altered without any more work on your part

Better example:


      

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to TNO)
 
 
Post #: 58
 
 RE: Array Expansion - 12/23/2006 3:50:47 AM   
  dm_4ever


Posts: 2432
Score: 38
Joined: 6/29/2006
From: Orange County, California
Status: offline
Thanks for the update. I've been following this thread intently.

Happy Holidays to All!!

_____________________________

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)
 
 
Post #: 59
 
 RE: Array Expansion - 12/23/2006 6:45:16 AM   
  TNO


Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Merry Christmas, the array Expansion is complete

Should we add and upgrade the Dictionary object too while we're at it? Got anything you'd like to add or change about it?

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to dm_4ever)
 
 
Post #: 60
 
 
Page:  <<   < prev  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 >> RE: Array Expansion Page: <<   < prev  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