Sign in to follow this  
Followers 0
PeterSwiss

How to Create a Collection

4 posts in this topic

How Do I, in VBScript, create a Collection?

such that, say, c("x")=1, v=c("x"), and FOR EACH y in c do work, as these statements do for built-in collections.

I searched the internet without success. Thanks for help. Peter

Share this post


Link to post
Share on other sites



I think this is what you are looking for, but not totally sure. Check the helpfile for the ObjCreate function. Here is a snippet from there.

$oShell = ObjCreate("shell.application")   ; Get the Windows Shell Object
$oShellWindows=$oShell.windows       ; Get the collection of open shell Windows

if Isobj($oShellWindows) then

  $string=""                   ; String for displaying purposes

  for $Window in $oShellWindows     ; Count all existing shell windows
    $String = $String & $window.LocationName & @CRLF
  next

  Msgbox(0,"Shell Windows","You have the following shell windows:" & @CRLF & @CRLF & $String);

endif
exit


; Example 2
;
; Open the MediaPlayer on a REMOTE computer
$oRemoteMedia = ObjCreate("MediaPlayer.MediaPlayer.1","name-of-remote-computer")

If not @error then
    Msgbox(0,"Remote ObjCreate Test","ObjCreate() of a remote Mediaplayer Object successfull !")
    $oRemoteMedia.Open("c:\windows\media\Windows XP Startup.wav")     ; Play sound if file is present
Else
    Msgbox(0,"Remote ObjCreate Test","Failed to open remote Object. Error code: " & hex(@error,8))
Endif

To me, that looks like what you are asking for. :lmao:

Share this post


Link to post
Share on other sites

I think this is what you are looking for, but not totally sure. Check the helpfile for the ObjCreate function. Here is a snippet from there.

To me, that looks like what you are asking for. :lmao:

Methos thanks for answering, but I was looking not for a list of windows, or mediaplayer, but for "Collections" in general. I found it myself. First, it needs to be a Dictionary. Second, the assignment statement for objects needs, in VBScript, always a "Set". Third it is not obligatory to use dictionarys Add method, one can write subscripts. As for example:

Dim c

Set c = CreateObject("Scripting.Dictionary")

c("a") = 1

c("b") = 2

c.Add "d", 4

'generate <br> c(x)=value

for each x in c

response.write "<br> c(" & x & ")=" c(x)

next

That's all it takes.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Methos thanks for answering, but I was looking not for a list of windows, or mediaplayer, but for "Collections" in general.

Well Peter, it's almost as easy in AutoIt as in VB:

$c = ObjCreate("Scripting.Dictionary")
$c.Item("a") = 1
MsgBox(0, "Dictionary", "Item a = " & c.Item("a))

Different is only that you don't need 'set' keyword for object assignments and there's no support for default properties in AutoIt, i.e. you can't use what you call 'subscripts' like c("a"), however c.Item("a") is exactly what VB does internally so it's equivalent.

Edited by Larry

UDFS & Apps:


DDEML.au3 - DDE Client + Server[*]
Localization.au3- localize your scripts[*]
TLI.au3 - type information on COM objects (TLBINF emulation)[*]
TLBAutoEnum.au3 - auto-import of COM constants (enums)[*]
AU3Automation - export AU3 scripts via COM interfaces
TypeLibInspector

- OleView was yesterday

Coder's last words before final release: WE APOLOGIZE FOR INCONVENIENCE 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0