Help with Type Mismatch

B

Brett

I have a form that calls a method within a DLL. By clicking a button on the
form, the DLL is instantiated and the SaveOutlookMessage() method invoked.
The DLL code copies messages from Outlook to an HTML file. When I execute
the EXE, which is only the form, and click the button, I get a "Type
Mismatch" error on this line in the form: mailobj.SaveOutlookMessage()

Any suggestions on why I'm getting the type mismatch error?

--Form code

Option Explicit Off
Public Class Form1
Private mailobj As OutlookSaveEmail.SaveOutlookMessage
Private Outlookobj As TestOutlookSaveEmail.Form1

Private Sub instantiate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles instantiate.Click
mailobj = New OutlookSaveEmail.SaveOutlookMessage
mailobj.SaveOutlookMessage() 'this line results in a type mismatch error
End Sub

End Class


--DLL code:

Public Class SaveOutlookMessage
Public Sub SaveOutlookMessage()
Dim fso As Object
Dim txtfile As Object
Dim myOlApp As Object
Dim myNamespace As Object
Dim myFolder As Object
Dim olFolderInbox As Object
Dim i As Integer
Dim myMailItems As String
olFolderInbox = ""
myMailItems = ""

fso = CreateObject("Scripting.FileSystemObject")
myOlApp = CreateObject("Outlook.Application")
myNamespace = myOlApp.GetNamespace("MAPI")
myFolder = myNamespace.GetDefaultFolder(olFolderInbox)

i = 1
Do Until i = 7
If myFolder.Items(i).Subject = "RE: Problem with mail" Then
If Len(myFolder.Items(i).HTMLBody) Then
myMailItems = myFolder.Items(i).HTMLBody
Else
myMailItems = myFolder.Items(i).Body
End If
End If
i = i + 1
Loop

txtfile = fso.CreateTextFile("C:\Myfiles\messages\" & "Testing" & ".html",
True)
txtfile.WriteLine(myMailItems)
txtfile.Close()
txtfile = Nothing
fso = Nothing
myOlApp = Nothing
myNamespace = Nothing
myFolder = Nothing
myMailItems = Nothing
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
End Class


Running .NET 2.0 framework.

Thanks,
Brett
 
J

John C. Kirk

Brett said:
I have a form that calls a method within a DLL. By clicking a button on the
form, the DLL is instantiated and the SaveOutlookMessage() method invoked.
The DLL code copies messages from Outlook to an HTML file. When I execute
the EXE, which is only the form, and click the button, I get a "Type
Mismatch" error on this line in the form: mailobj.SaveOutlookMessage()

Any suggestions on why I'm getting the type mismatch error?

From a quick glance at your code, I'm guessing that the error is actually
inside the SaveOutlookMessage procedure, rather than in the line where it's
called, so if you adjust your exception handling then you can track it down
more precisely. What I'd also recommend is that you use:
Option Strict On
Option Explicit On
at the start of each module, and then use early binding, rather than having
declarations like "Dim fso As Object". That way, any problems will show up
at compile-time rather than at run-time.

John
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top