calling .NET from VBA: one parameter only in a method?

  • Thread starter Thread starter Bobby
  • Start date Start date
B

Bobby

Hello,

I'm seeing strange behavior experimenting with calling .NET. If I
create a project in .NET 2k3 and select 'interop assembly' it will
create the CCW for me, correct?

I created a class library with this class in it:
Public Class TestCCW
Public Sub Stream(ByVal filename As String)
MsgBox("filename is '" & filename & "'")
End Sub
Public Sub Stream2(ByVal filename As String, ByVal tmp As
String)
MsgBox("filename is '" & filename & "' tmp is '" & tmp &
"'")
End Sub
Public Sub Stream3(ByRef filename As String)
MsgBox("filename is '" & filename & "' ")
End Sub
Public Sub Stream4(ByRef filename As String, ByRef tmp As
String)
MsgBox("filename is '" & filename & "' tmp is '" & tmp &
"'")
End Sub
End Class

I build it successfully, and in Access 2k2 I make the following VBA
calls (tied to a button click):
Private Sub Command1_Click()
Dim tmp As XSDLib3.DaoSdr
Set tmp = New XSDLib3.DaoSdr
Dim rs As DAO.Recordset
Set rs = Me.Recordset
tmp.Stream ("foo")
' Compile error: Syntax error
'tmp.Stream2("stream2","bar")
tmp.Stream3 ("stream3")
' Compile error: Syntax error
'tmp.Stream4("stream4","bar")
Set tmp = Nothing
End Sub

I thought at first it might be a ByRef vs. ByVal problem, hence Stream
vs. Stream3 (which work succesffully). But that wasn't the case

Can anybody advise me as to why stream2 and stream4 fail with compile
errors?

Thanks
 
Hello,

I'm seeing strange behavior experimenting with calling .NET. If I
create a project in .NET 2k3 and select 'interop assembly' it will
create the CCW for me, correct?

I created a class library with this class in it:
Public Class TestCCW
Public Sub Stream(ByVal filename As String)
MsgBox("filename is '" & filename & "'")
End Sub
Public Sub Stream2(ByVal filename As String, ByVal tmp As
String)
MsgBox("filename is '" & filename & "' tmp is '" & tmp &
"'")
End Sub
Public Sub Stream3(ByRef filename As String)
MsgBox("filename is '" & filename & "' ")
End Sub
Public Sub Stream4(ByRef filename As String, ByRef tmp As
String)
MsgBox("filename is '" & filename & "' tmp is '" & tmp &
"'")
End Sub
End Class

I build it successfully, and in Access 2k2 I make the following VBA
calls (tied to a button click):
Private Sub Command1_Click()
Dim tmp As XSDLib3.DaoSdr
Set tmp = New XSDLib3.DaoSdr
Dim rs As DAO.Recordset
Set rs = Me.Recordset
tmp.Stream ("foo")
' Compile error: Syntax error
'tmp.Stream2("stream2","bar")
tmp.Stream3 ("stream3")
' Compile error: Syntax error
'tmp.Stream4("stream4","bar")
Set tmp = Nothing
End Sub

I thought at first it might be a ByRef vs. ByVal problem, hence Stream
vs. Stream3 (which work succesffully). But that wasn't the case

Can anybody advise me as to why stream2 and stream4 fail with compile
errors?

Thanks

This is a longshot, but since Stream, Stream2, Stream3 and Stream4 are
subs, you need to call them without using parentheses:

tmp.Stream "foo"
tmp.Stream2 "stream2", "bar"
tmp.Stream3 "stream3"
tmp.Stream4 "stream4", "bar"

Not sure if this is the problem, but it's worth checking.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Back
Top