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

From: Roderick McGuire (mcguire at telerama.com)
Date: Fri Mar 26 17:36:16 EST 2004

I'm interacting with MzCom from MS Excel via Visual Basic. While I can 
write some VB I'm not really competent. Non the less, most things seem 
to be working. The code I've included below can also be found in the 


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

Private Sub MzCom_SchemeError(s As String)
     MsgBox ("Scheme Error: " + s)
End Sub

I noticed that Andre Van Meulebrouck, in his test program (found on this 
page: http://www.cs.utah.edu/plt/develop/ ) never does anything with the 
SchemeError event so I don't know if it is even working. Nor am I 
competent enough in VB to know how to tell.

My version is Excel 2002 as part of Office 10.

P.S. Is there some less ugly way to write the "slashify" function below?

Dim initted As Boolean
Dim MzCom As New MzObj

Public Sub MzComREPL()
     Dim sin, sout As String
     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()
     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 Sub MzCom_SchemeError(s As String)
     MsgBox ("Scheme Error: " + s)
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 = ""
         If "\" = Left$(s, 1) Then
             slashify = "\\" + slashify(Right$(s, sl - 1))
             slashify = Left$(s, 1) + slashify(Right$(s, sl - 1))
         End If
     End If
End Function

Posted on the users mailing list.