Collections: Difference between revisions

Line 1,882:
Sets
</lang>
 
===Using a Visual Basic 6 Collection===
M2000 Interpreter is a VB6 application. We can use a VB6 collection, but only until the module where we declare it end. This is what this interpreter do with COM objects, it never make a second object reference (we can make other variables as reference, using the same object, and these reference can't changed). We can pass object through stack of values, but for a call inside the M2000 interpreter. In this example we make a lambda function which hold a closure, and this closure works only if the object exist.
 
We can get a list
<lang M2000 Interpreter>
Module GetC {
declare c collection
Document doc$
Print type$(c)
\\ we get an inventory list of all methods/properties of a com Object
m=param(c)
IF LEN(m)>1 THEN {
For i=0 to len(m)-1
\\ use index, not key so i! is index
Doc$=m$(i!)+{
} ' we use this block for new line
Next i
}
Report Doc$
\\ so now we have to use it, using Methid to call Add
Method c, "Add", 100, "Hello"
Method c, "Add", 2000, "There"
\\ add a decimal number
Method c, "Add", 3000032131231231312312@, "Zero"
Method c, "count" as count
Print count =3 ' we have three members
Method C, "_NewEnum" as Item
Method c, "Item", "Zero" as ZeroItem ' we get the decimal number
Print ZeroItem
Print type$(Item)="Nothing" ' we have numbers
k=0
While Item {
k++
print k, eval(item)
}
c.item=lambda c (akey$) ->{
try ok {
method c, "item", akey$ as ret
}
If type$(Ret)="Empty" Then Error "Key not used"
=ret
}
Print c.item("Hello")
Try {
val=c.item("Hello12")
}
Print Error$
Push c
\\ normaly we can use this line
\\ but if we omit this, Interpreter do this for us
Rem : Declare c Nothing
}
\\ we can't use a com object out of scope (because automatic change to Nothing, and the object released)
GetC
Read a
Print type$(a)="Nothing"
</lang>
ed{Out}
<pre>
Function QueryInterface(riid, ppvObj)
Function AddRef
Function Release
Function GetTypeInfoCount(pctinfo)
Function GetTypeInfo(itinfo, lcid, pptinfo)
Function GetIDsOfNames(riid, rgszNames, cNames, lcid, rgdispid)
Function Invoke(dispidMember, riid, lcid, wFlags, pdispparams, pvarResult, pexcepinfo, puArgErr)
Function Item(Index)
Function Add(Item, Key, Before, After)
Function Count
Function Remove(Index)
Function _NewEnum
True
3000032131231231312312
True
1 100
3 2000
33000032131231231312312
100
Key not used Problem in lambda in function C.ITEM(
True
</pre>
 
=={{header|Maple}}==
Defining lists:
Anonymous user