I'm converting an old VB6 app to PB and I'm encountering a problem converting code that utilizes a 3rd-party tool called OSSMTP to send automated emails. I can convert the code to enable sending of the email from PB, but I can't capture an error when one occurs.
Here's the OSSMTP object model: http://ostrosoft.com/ossmtp/ossmtp_reference.aspx
In VB6, there's a concept called Dim WithEvents that can be declared as follows:
Dim WithEvents oSMTP As OSSMTP.SMTPSession
Then we can define our SendMail method:
Private Sub SendEmail()
On Error GoTo EH_SendEmail
DoEvents '*** needed to ensure email logic does not conflict with modals ***
Set oSMTP = New OSSMTP.SMTPSession
With oSMTP
.Server = ???
.Port = ???
.AuthenticationType = ???
.UserName = ???
.Password = ???
.UseSSL = ???
.MailFrom = ???
.ReplyTo = ???
.SendTo = ???
.CC = ???
.BCC = ???
.MessageSubject = ???
.MessageText = ???
.Importance = 0
.Notification = 0
.Sensitivity = 0
'Send the email.
.SendEmail
End With
Set oSMTP = Nothing
Exit Sub
EH_SendEmail:
Call goError.GeneratedMessage(Error$, CLASS_NAME & "->SendEmail")
If Not oSMTP Is Nothing Then
Set oSMTP = Nothing
End If
End Sub
And finally the custom event that gets triggered when there's an error:
Private Sub oSMTP_ErrorSMTP(ByVal Number As Integer, Description As String)
Dim sMessage As String
sMessage = "Unable to send the automated " & m_sEmailType & " e-mail!"
sMessage = sMessage & vbCrLf & vbCrLf & "Please report the following information to the Service Desk:"
sMessage = sMessage & vbCrLf & vbCrLf & "Error " & Number & ": " & Description
MsgBox sMessage, vbCritical + vbOKOnly, App.Title
'MsgBox "Error " & Number & ": " & Description, vbCritical + vbOKOnly, App.Title
End Sub
There doesn't seem to be any equivalent to Dim WithEvents in Powerbuilder.
I've tried to implement it using TRY ... CATCH blocks with exception/runtimeerror/oleruntimeerror objects, but nothing seems to work. (see attached file)
I feel like I'm missing something really basic, but I can't seem to figure out what that is.
Has anyone done anything similar where they can offer some advice?