Jump to content

Recommended Posts

Posted

I found this article

net framework and vbscript (sorry, it is in italian).

The meaning is that you can use some classes of the net framework in your script.

So i tried to do something like that:

Func F_test()
    $list=ObjCreate("System.Collections.sortedlist")
    $list.add("z","sappa")
    $list.add("f","asa")
    $list.add("a","dfdsappa")
    $list.add("h","qqwrtsappa")
    ConsoleWrite("test: "&$list.count&@crlf)
    for $i=0 to $list.count-1
        ConsoleWrite($list.GetKey($i)&" - "&$list.Getbyindex($i)&@crlf)
    Next
EndFunc

IT works. It could be very helpful.

Someone knows something about that?

Someone knows other net classes we can use in scripting?

Posted
Posted

@gadzail

I like this one. I am constantly looking for new objects myself, and this one I didn't have yet.

Good job.

Better next time is to post your examples in the EXAMPLE SCRIPT section of the forum.

Ciao !!

ptrex

OKS ptrex.

You are right, It is better. I don't want to duplicate the post, maybe the admin can move it.

I would like to know which net classes we can use in scripting.

if someone find something please reply...

Posted (edited)

This is FANTASTIC!!! I wish I'd known about this a year ago!

It looks like .Net members in registered DLLs with the COMVisible(True) attribute or an assigned GUID are available for scripting. This includes the following potentially useful items:

  • System.Collections.ArrayList
  • System.Collections.HashTable
  • System.Collections.SortedList
  • System.Collections.Stack
  • System.Collections.Queue
  • System.Diagnostics.Debugger
  • System.Diagnostics.StackFrame
  • System.Diagnostics.StackTrace
  • various calendars and Info classes in System.Globalization
  • System.IO.MemoryStream
  • System.IO.StringWriter
  • System.Random
  • a LOT of things in System.Runtime.InteropServices and System.Runtime.Remoting
  • System.Text.ASCIIEncoding
  • System.Text.StringBuilder
  • System.Text.UnicodeEncoding
  • System.Threading.Mutex
  • System.Threading.OverLapped
  • System.Threading.ReaderWriterLock
I just did a bit of experimenting to see if SortedList would handle AutoIt-style arrays and DLLStruct variables. It turns out, Arrays work great, but DLLStructCreate seems to return something that can't be stored. One way around that is to use Assign() and Eval():

#include <array.au3>
    $rect=DllStructCreate("int;int;int;int")
;~  MsgBox(0,"DLLStructCreate errorlevel", @error)
    DllStructSetData($rect,1,10)
    DllStructSetData($rect,2,20)
    DllStructSetData($rect,3,64)
    DllStructSetData($rect,4,48)
;~  MsgBox(0,$rect & "[ 3 ]", DllStructGetData($rect,3))

    ; Assign the structure to a named variable. The DLLStruct can't be serialized effectively with this technique, but it can be dereferenced using Eval.
    Assign("rectstructure",$rect) 
    
    $array=_ArrayCreate("1","2","3","4","a","b","c","d")
    
    $list=ObjCreate("System.Collections.SortedList")
    $list.add("z","sappa")
    $list.add("f","asa")
    $list.add("a","dfdsappa")
    $list.add("h","qqwrtsappa")
    $list.add("autoitarray",$array)
    $list.add("rectstruct","rectstructure")
    
    ConsoleWrite("test: " & $list.count & @crlf)
    for $i=0 to $list.count-1
        $key=$list.GetKey($i)
        $value=$list.Getbyindex($i)
        If Not IsArray($value) Then 
            ConsoleWrite($key & " - " & $value & @crlf)
        Else
            ConsoleWrite($key & " - ")
            For $j=0 to UBound($value)-1
                ConsoleWrite($value[$j] & "    ")
            Next
            ConsoleWrite(@crlf)
        EndIf           
    Next
    
ConsoleWrite("Rect structure with reference stored in sorted list:" & @CRLF)
ConsoleWrite("x1: " & DllStructGetData(Eval($list("rectstruct")),1) & @CRLF)
ConsoleWrite("y1: " & DllStructGetData(Eval($list("rectstruct")),2) & @CRLF)
ConsoleWrite("x2: " & DllStructGetData(Eval($list("rectstruct")),3) & @CRLF)
ConsoleWrite("y2: " & DllStructGetData(Eval($list("rectstruct")),4) & @CRLF)

This outputs:

test: 6
a - dfdsappa
autoitarray - 1 2   3   4   a   b   c   d   
f - asa
h - qqwrtsappa
rectstruct - rectstructure
z - sappa
Rect structure with reference stored in sorted list:
x1: 10
y1: 20
x2: 64
y2: 48
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 10.077

(Yes, I know, the time on that is ridiculous - I think it is counting the compilation time from AU3Wrapper, though. A message box at the start of the script gives a reference point from which execution is almost instantaneous. Has anyone else noticed this?)

I look forward to hearing others' experiences with this. This is an incredible discovery, gadzail!

Edited by sohfeyr
  • 2 weeks later...
Posted

hi

this is awesome !!

i like to have hashtables in auto it , now i can :-))

; http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

$hash = ObjCreate("System.Collections.Hashtable")
$hash.add ("txt", "notepad.exe")
$hash.add ("bmp", "paint.exe")
$hash.add ("dib", "paint.exe")
$hash.add ("rtf", "wordpad.exe")

ConsoleWrite("For key = 'bmp', value = " & $hash ("bmp") & @CRLF)
ConsoleWrite("For key = 'rtf', value = " & $hash ("rtf") & @CRLF)
  • 7 years later...

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
  • Recently Browsing   0 members

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