How to Call scripts

Started by heifler, August 09, 2009, 05:51:12 PM

Previous topic - Next topic

heifler

I code in VBA MS Access.  I see great scripts and have loaded newLISP.  

I have some VBA code to run newLISP in MS Access database.  I have successfully called some basic functions but would like to know how to call a script as seen in http://www.newlisp.org/syntax.cgi?code/twitter.txt">http://www.newlisp.org/syntax.cgi?code/twitter.txt

from MS Access.  

 



Here is some code I have so far in a public module:



Option Compare Database



Public Declare Function dllNewlispEval Lib "NewLisp" Alias "newlispEvalStr" (ByVal LExpr As String) As Long

Private Declare Function LoadLibraryA Lib "kernel32" (ByVal s As String) As Long

Private Declare Sub FreeLibrary Lib "kernel32" (ByVal h As Long)

Declare Function lstrLen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long

Declare Function lstrCpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long



Dim NewlispHandle As Long



Sub Auto_Open()

  LoadNewLISP

End Sub



Public Sub LoadNewLISP()

    Dim mylib As String

    Dim hinst As Long

    Dim LibPath As String

    mylib = "C:Program Filesnewlispnewlisp.dll"

    NewlispHandle = LoadLibraryA(mylib)

    If NewlispHandle = 0 Then

        MsgBox "Can not find C:Program Filesnewlispnewlisp.dll on this machine."

    End If

End Sub



Function NewLisp(LispExpression As String) As Variant

    Dim Result As String

    Dim ResHandle As Long

    Dim ResultCode As Long

    ResHandle = dllNewlispEval(LispExpression)

    Result = Space$(lstrLen(ByVal ResHandle))

    lstrCpy ByVal Result, ByVal ResHandle

    NewLisp = Result

End Function



Public Sub Auto_close()

  UnloadNewLISP

End Sub



Sub UnloadNewLISP()

    FreeLibrary NewlispHandle

End Sub



Public Function CreateLispScript(strUser As String, pw As String) As Variant

Dim strScript As String

strScript = "(+ 8 3)"

CreateLispScript = NewLisp(strScript)

End Function



Private Sub Command0_Click()

Dim str As Variant

 

Call LoadNewLISP

 MsgBox CreateLispScript("TwitterName", "TwitterPassword")

 Call Auto_close

End Sub



Bob Heifler

cormullion

#1
QuotestrScript = "(+ 8 3)"


This looks like a newLISP expression adding 8 and 3. If it works, and you can somehow, somewhere, see the answer, then you know how to evaluate a newLISP expression! :)



Another newLISP expression you can evaluate is:


(load "script.lsp")

this evaluates every expression in the named script file. If the script does something useful when expressions are evaluated - many do - you're home and dry. If, however, the script is more of a module or library, it won't actually do anything, until you ask to evaluate another expression that makes use of the module's code.



If you can't see the answer of a newLISP expression, or if I've gone completely off the rails, then perhaps someone with more (any) experience of VBA and Windows can help. A quick search proposes http://www.alh.net/newlisp/phpbb/viewtopic.php?t=809">//http://www.alh.net/newlisp/phpbb/viewtopic.php?t=809 and http://www.newlisp.org/code/VBA.zip">//http://www.newlisp.org/code/VBA.zip for starters...

xytroxon

#2
To execute another program script and capture the output.



; Note: use {"...."} string form for windows path names

; newlisp program (or any windows program with stdout)
(set 'program_path {"c:program filesnewlispnewlisp.exe"})

; local copy of newlisp script
(set 'script_path {"d:newlisptwittertwitter.nl"})

; add any script options, etc. here
(set 'options "")

; join command list, execute and capture results
(set 'results (exec (join (list program_path script_path options) " ")))

; process program output lines or errors
(println results)



-- xytroxon
\"Many computers can print only capital letters, so we shall not use lowercase letters.\"

-- Let\'s Talk Lisp (c) 1976