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/19/2006 8:29:13 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
I have exposed COM objects from wsc files via type libraries before. It is a pain in the rear and I refuse to ever do it again, but here are my links for the web pages that I used to figure it out:

http://www.microsoft.com/mind/1299/cutting/cutting1299.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/4e03d38c-38eb-4737-b5e6-365a2e57d422.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/c15cf8bf-4c7b-474e-bf02-d355f5593d60.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/e1ecc9c8-3762-465d-8bd7-60d8ba685252.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/46e2ec71-bed6-4549-ac61-d1b313a643ce.asp

These days if I feel the urge to create a COM component, I either slam a door on my head a couple of times or else I do it in a full blown programming language.

_____________________________

"... 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 #: 21
 
 RE: Array Expansion - 12/19/2006 8:48:52 AM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
There is some kind of bug with JS.Pop()....can't figure it out yet. I even rewrote the function 3 different ways.

Thanks for the links ebgreen

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ebgreen)
 
 
Post #: 22
 
 RE: Array Expansion - 12/19/2006 9:16:20 AM   
  TNO


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

or else I do it in a full blown programming language


I think i feel insulted for the vb/jscripters out there

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 23
 
 RE: Array Expansion - 12/19/2006 11:38:29 AM   
  dm_4ever


Posts: 2174
Score: 32
Joined: 6/29/2006
From: Orange County, California
Status: offline
I can't believe you took the time to put this together.  PrimalScript makes it easy to put a WSC together with the necessary info to make it viewable in a typelib browser. I used it to create a WSC with the code you put together. Below is the difference that allows for this up to the point where the
<public>
           <method name="Concat">

of yours comes in.


      

_____________________________

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 #: 24
 
 RE: Array Expansion - 12/19/2006 5:15:03 PM   
  TNO


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

I can't believe you took the time to put this together




THis only took about an hour and a half in notepad

quote:

PrimalScript makes it easy to put a WSC together with the necessary info to make it viewable in a typelib browser.....


Thanks for the registration info. I've added. (It doesn't create the tags totally right, but it did 90% of the work)

<?xml version="1.0" ?>
<package>
   <comment>
   </comment>
   <component id="JSArray">
   <?component error="true" debug="true" ?>
   <registration progid="JS.Array" classid="{EC189C13-F413-4BBC-AE90-9A2083E5A090}" description="JSArray" version="1.0">
       <script language="VBScript">
       <![CDATA[
           Function Register()
               Dim TypeLib
               Set TypeLib = CreateObject("Scriptlet.TypeLib")
               TypeLib.AddURL "JSArray-v1.WSC"
               TypeLib.Path = "JSArray-v1WSC.tlb"
               TypeLib.Doc = "JSArray-v1"
               TypeLib.Name = "JSArray-v1WSC.tlb"
               TypeLib.MajorVersion = 1
               TypeLib.MinorVersion = 0
               TypeLib.Write
           End Function

           Function Unregister()

           End Function
       ]]>
       </script>
   </registration>


Now viewable in the object browser, awesome.

The Pop() bug has been fixed thanks to some help from a colleague (russell) at Webdeveloper.com

It should be noted though that Pop() and Shift() don't work the way they do in JScript. In my version these two methods return the remaining array. In JScipt it returns the first or last element and just alters the array without returning it (I didn' see the point of this).

The updated file has been uploaded:

http://www.thenewobjective.com/website/development/JavaScript/Components/vbsArrays/JSArray-v1.wsc

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to dm_4ever)
 
 
Post #: 25
 
 RE: Array Expansion - 12/19/2006 5:52:01 PM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Bug with JS.Push() ....

Probably something to do with Array translation between the languages. hmm....

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 26
 
 RE: Array Expansion - 12/19/2006 11:53:24 PM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
JS.Push() fixed, and a couple functions translated into 100% vbscript

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 27
 
 RE: Array Expansion - 12/20/2006 12:06:26 AM   
  ginolard


Posts: 1005
Score: 21
Joined: 8/10/2005
Status: offline
Odd.  I don't have a "Register" option when right-clicking on the file.

_____________________________

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 #: 28
 
 RE: Array Expansion - 12/20/2006 12:26:35 AM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
I made a couple more changes and uploaded the updated file. 

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to ginolard)
 
 
Post #: 29
 
 RE: Array Expansion - 12/20/2006 1:48:51 AM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Concat() Will now let you combine as many arrays as you want instead of just two

Example:


      

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 30
 
 RE: Array Expansion - 12/20/2006 2:33:07 AM   
  dm_4ever


Posts: 2174
Score: 32
Joined: 6/29/2006
From: Orange County, California
Status: offline
To add the option to Register or unregister. I had a similar problme on a different PC.

My Computer > Tools > Folder Options > File Types > Locate WSC and select it > click the advanced button

Actions:
   Action:  Generate Type Library
   Application userd....:  "C:\WINDOWS\system32\RUNDLL32.EXE" C:\WINDOWS\system32\scrobj.dll,GenerateTypeLib "%1"
   Use DDE: Checked
   Application:  scrobj
   Topic:  System
  
   Action:  Register
   Application userd....:  "C:\WINDOWS\system32\REGSVR32.EXE" /i:"%1" "C:\WINDOWS\system32\scrobj.dll"
   Use DDE: Checked
   Application:  REGSVR32
   Topic:  System
  
   Action:  Unregister
   Application userd....:  "C:\WINDOWS\system32\REGSVR32.EXE" /u /n /i:"%1" "C:\WINDOWS\system32\scrobj.dll"
   Use DDE: Checked
   Application:  REGSVR32
   Topic:  System

_____________________________

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 ginolard)
 
 
Post #: 31
 
 RE: Array Expansion - 12/20/2006 2:36:40 AM   
  dm_4ever


Posts: 2174
Score: 32
Joined: 6/29/2006
From: Orange County, California
Status: offline
TNO,

Awesome job again!! 

_____________________________

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 #: 32
 
 RE: Array Expansion - 12/20/2006 2:51:14 AM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Alright, significant update this time. I translated more functions into vbscript with some help from my JavaScript colleague again (I'll post all the credit when we finally finish)

Heres a quick overview over the new function list
(<---Function is complete and passed all bug tests)
(<--Function is not working or is bugged)

Concat(Array1,Array2,Array3.......Arrayn)
Returns a new array consisting of a combination of two or more arrays.
Ex:

      

Index(Array1,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

Ex:

      

Del(Array1,Index)
Deletes an Element in the array and resizes the original array to its new value:
Ex:


      

Insert(Array1,Index,Value)
Insert a new value at the Index and automatically resize the array
Ex:

      

LastIndex(Array1,Value,Bottom Limit,Strict)
Returns the Last 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
Bottom Limit-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:
Ex:

      

Length(Array1)
Return the Length of an array
Ex:

      

Pop(Array1)
Removes the last element from an array, the original array is altered
Ex:

      

Push(Array1,Value)
Adds an Item to the end of an Array. The  original array is altered:
Ex:

      

Random(Array1)
Return a random element from the array
Ex:


      

Reverse(Array1)
Reverses the order of the array
Ex:


      

Replace(
Array1,Index,Value)
Replace a value at the Index with the new value

      

Shift(Array1)

Shuffle(Array1)

Slice(Array1,StartI,EndI)

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

Ex:

      

Splice(Array1,Start,DelCount,Array2)

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 ""
Ex:

      

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

      

Undupe(Array1)
Removes Duplicates from Array and returns the new array
Ex:

      

UnShift(Array1,Value)
Adds Element to the begginning of Array1 and returns the new array
Ex:

      

< Message edited by TNO -- 12/21/2006 11:58:55 PM >


_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 33
 
 RE: Array Expansion - 12/21/2006 4:26:54 AM   
  TNO


Posts: 1036
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status: offline
Would someone mind giving me a dummy class on the difference between passing an argument to a VBScript Function ByVal and ByRef? I don;t think I'm doing it entirely correct and am getting improper results on a couple of these

_____________________________

Consolidated Script Component: The Acid Test

A universe of complexity...

(in reply to TNO)
 
 
Post #: 34
 
 RE: Array Expansion - 12/21/2006 4:28:56 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
ByVal passes a copy of the var/object. ByRef passes a reference to the actual var/object.

_____________________________

"... 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 #: 35
 
 RE: Array Expansion - 12/21/2006 4:42:04 AM   
  ebgreen


Posts: 4595
Score: 29
Joined: 7/12/2005
Status: offline
Here is code to show the difference:

strTest = "Start"
WScript.Echo "Before calling ByRefExample. strTest = " & strTest
ByRefExample strTest
WScript.Echo "After calling ByRefExample. strTest = " & strTest
WScript.Echo "Calling ByValExample"
ByValExample strTest
WScript.Echo "After calling ByValExample. strTest = " & strTest

Sub ByRefExample(ByRef strFoo)
   'This one will alter the value of the variable passed In
   strFoo = "Changed in ByRefExample"
End Sub

Sub ByValExample(ByVal strFoo)
   'This one will not alter the value of the variable passed in
   strFoo = "Changed in ByValExample"
   WScript.Echo vbTab & "In the ByValExample Sub, strFoo = " & strFoo
End Sub

The output is:

Before calling ByRefExample. strTest = Start
After calling ByRefExample. strTest = Changed in ByRefExample
Calling ByValExample
   In the ByValExample Sub, strFoo = Changed in ByValExample
After calling ByValExample. strTest = Changed in ByRefExample

_____________________________

"... 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 #: 36
 
 RE: Array Expansion - 12/21/2006 4:58:42 AM   
  ehvbs

 

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

I'm very interested in your project. I learned a lot by my first walk thru your code,
and I want to put some code behind my feelings. Because I think of you as a programmer
interested in speed, I reworked my old Sort benchmark from this forum. I used this
as a test if I could get your component to work on my machine - success, no problems
at all - you may use it to test and demonstrate the quality and speed of your code.

The benchmark provides for Insertion Sort (thanks ebgreen), Sort via .NET ArrayList
(needs Runtime 1.1 or greater) and my first attempt of using JSArray.Sort(). Selecting
methods/data samples/sizes shouldn't be difficult for anybody seriously interested
in this topic (but feel free to ask).