[plt-scheme] Anyone competent in VB? MzCom & Excel question.

From: Martial Tarizzo (tarizzo at metz.supelec.fr)
Date: Fri Mar 26 20:09:36 EST 2004

The problem is not in MzCom, but in your code. See below.

Martial Tarizzo
Physics Teacher - Metz - France

> The one problem I'm having is that I don't seem to be able to catch 
> SchemeError events. Being able to would really help in debugging. I 
> think this is the right way to do it but the code below is never
> invoked.
> 
> Private Sub MzCom_SchemeError(s As String)
>      MsgBox ("Scheme Error: " + s)
> End Sub
> 

You have to modify/add the lines with ***********
=========
Dim initted As Boolean
Dim WithEvents MzCom As MzObj *********************
' WithEvents -> you have now a new "object" in the left comboBox above the
editor, *************
' with  MzCom_SchemeError as its event in the right one...
******************

Public Sub MzComREPL()
    Dim sin, sout As String
    initialize
    On Error GoTo 20
    sin = "'ready"
10  sout = MzCom.Eval(sin)
    sin = InputBox(sout)
    If Not sin = "" Then GoTo 10
    Exit Sub
20  MsgBox ("repl: " & Err.Number & vbCrLf & Err.description)
    initted = False
 '   Err.Clear
 End Sub
  
Private Sub initialize()
Set MzCom = New MzObj  ****************** object initialization
    On Error GoTo 10
    If initted = False Then
        MsgBox ("initting")
        ' HAVE MzCom load some functions here
        MzCom.Eval ("(current-directory " +
Quote(slashify(ThisWorkbook.Path)) + ")")
        initted = True
    End If
    Exit Sub
10  MsgBox ("init: " & Err.Number & vbCrLf & Err.description)
End Sub



Private Function Quote(s As String) As String
    Quote = Chr$(34) + s + Chr$(34)
End Function

Private Function slashify(s As String) As String
    Dim sl As Integer
    sl = Len(s)
    If sl = 0 Then
        slashify = ""
    Else
        If "\" = Left$(s, 1) Then
            slashify = "\\" + slashify(Right$(s, sl - 1))
        Else
            slashify = Left$(s, 1) + slashify(Right$(s, sl - 1))
        End If
    End If
End Function

Private Sub MzCom_SchemeError(ByVal description As String)************** 
' ByVal mandatory, (ByRef is the default in VB) ******************
 MsgBox ("Scheme Error: " + description)
End Sub
========================





Posted on the users mailing list.