Jump to content

How to Create a Collection


PeterSwiss
 Share

Recommended Posts

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:

Link to comment
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.

Link to comment
Share on other sites

  • 4 weeks later...

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:

Spoiler

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Ā 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...