Hi,
The VisualLisp Activex Model is in
VL.tlb
Dim VL As Object
Sub test()
' Get the VisualLisp Automation
interface
Set VL =
CreateObject("VL.Application.1")
'
' Getting symbols and lists from
Lisp
'
' Get the value of the
Lisp symbol 'a'.
' Use (setq a 1234) in Lisp to set
it.
a = GetLispSym("a")
Debug.Print "symbol a
is: " & a
' Get the Lisp list 'b'.
Use
' (setq b (list 100 1.234 "string"))
' in
Lisp to define it.
b = GetLispList("b")
Debug.Print "list b contains:"
For Index = LBound(b) To
UBound(b)
Debug.Print b(Index)
Next
'
' Setting Lisp symbols
and lists
'
' Set the Lisp
symbol 'c' to 100.0
Dim value As Double
value =
100#
PutLispSym "c", value
' Create the list
' ("VBA" 100
1.234)
' and store it in the Lisp symbol 'd'.
Dim values(0 To 2) As Variant
values(0) = "VBA"
values(1) = 100
values(2) = 1.234
PutLispList "d", values
End
Sub
' This function returns the value of
' a Lisp
symbol.
' The Lisp symbol can be set in Lisp like:
' (setq x
1234)
Function GetLispSym(symbolName As String) As Variant
Dim sym As Object
If VL Is Nothing
Then
Set VL =
CreateObject("VL.Application.1")
End If
' Get the Lisp symbol 'symbolName'.
Set sym =
VL.ActiveDocument.Functions.Item("read").funcall(symbolName)
GetLispSym =
VL.ActiveDocument.Functions.Item("eval").funcall(sym)
End
Function
' This function gets a Lisp list
' and put its
elements into a
' Variant array.
' The list can be something like:
'
(100 1.234 "string")
Function GetLispList(symbolName As String) As
Variant
Dim sym As Object
Dim
list As Object
If VL Is Nothing
Then
Set VL =
CreateObject("VL.Application.1")
End If
' Get the Lisp symbol
'symbolName'.
Set sym =
VL.ActiveDocument.Functions.Item("read").funcall(symbolName)
Set
list = VL.ActiveDocument.Functions.Item("eval").funcall(sym)
' Get the number of elements in this list.
Items = VL.ActiveDocument.Functions.Item("length").funcall(list)
ReDim VarItems(0 To Items - 1) As Variant
' Get every item from the list.
For i = 1 To
Items
Item =
VL.ActiveDocument.Functions.Item("nth").funcall(i - 1,
list)
VarItems(i - 1) = Item
Next
GetLispList = VarItems
End Function
' This function creates a new Lisp symbol
'symbolName'.
' It gets the value specified by 'value'.
Sub
PutLispSym(symbolName As String, value As Variant)
Dim sym As Object
If VL Is Nothing
Then
Set VL =
CreateObject("VL.Application.1")
End If
Set sym =
VL.ActiveDocument.Functions.Item("read").funcall(symbolName)
VL.ActiveDocument.Functions.Item("set").funcall sym,
value
End Sub
' This function creates a new Lisp list
' and
assigns it to the symbol 'symbolName'.
' The 'values' parameter has to
contain
' an array of variants, and this array
' is converted to the Lisp
list:
' Array: "VBA" 100 1.234
' List: ("VBA" 100 1.234)
Sub
PutLispList(symbolName As String, values As Variant)
' Initialize the list using the first
value.
Dim list As Object
Dim
newList As Object
If VL Is Nothing
Then
Set VL =
CreateObject("VL.Application.1")
End If
Set list =
VL.ActiveDocument.Functions.Item("list").funcall(values(0))
' Append the other
items
For Item = LBound(values) + 1 To
UBound(values)
' Create a new list for the next
item...
Set newList =
VL.ActiveDocument.Functions.Item("list").funcall(values(Item))
' ...and append it to the existing list.
Set list =
VL.ActiveDocument.Functions.Item("append").funcall(list,
newList)
Next
' Assign the new
list to 'symbolName'
Dim sym As Object
Dim res
As Object
Set sym =
VL.ActiveDocument.Functions.Item("read").funcall(symbolName)
Set
res = VL.ActiveDocument.Functions.Item("set").funcall(sym, list)
End Sub
Regards,
Pierre
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
see
topic