Passing Variables to VBA

Discussion in 'AutoCAD' started by Mel, Jul 24, 2003.

  1. Mel

    Mel Guest

    Is there a way to pass variables from AutoLisp to VBA programs? Like a
    command line option or something.

    Any help would be GREATLY appreciated ;)
     
    Mel, Jul 24, 2003
    #1
  2. Mel

    Lansch Guest

    Frank, VLAX has been a very useful tool in several of my VBA subs to cover some of the things that can't be done in VB (such as creating a 'boundary'). What i have done to get LISP and VBA to talk back and forth is to write VBA functions 'SetEnv' and 'GetEnv 'to compliment the ones in AutoCAD:



    Public Sub SetEnv(VarName As String, Value As String)     On Error Resume Next     Dim VL As vlax     Set VL = New vlax     Dim strExpression As String     strExpression = "(setenv """ & VarName & """ """ & Replace(Value, "\", "\\") & """)"     If LISP_DEBUG Then Debug.Print strExpression

    VL.EvalLispExpression strExpression     Set VL = Nothing End Sub

    Public Function GetEnv(VarName As String, Optional DefaultValue As String) As String     On Error Resume Next     Dim VL As vlax     Set VL = New vlax     Dim strExpression As String     Dim ReturnValue As Variant     strExpression = "(getenv """ & VarName & """)"     If LISP_DEBUG Then Debug.Print strExpression

    ReturnValue = VL.EvalLispExpression(strExpression)     Set VL = Nothing

    If ReturnValue = "" And DefaultValue <> "" Then         GetEnv = DefaultValue     Else         GetEnv = ReturnValue     End If End Function

    <\pre> The reason i take this route is to save variables so the next time they open AutoCAD, everything is ready to go. The only real downfall is that the values are always stored in strings -- but easy enough to work around.



    - Lanny
     
    Lansch, Jul 25, 2003
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.