Most methods and properties that you call will generate an error if something is not right, these errors can be trapped and you can do your own thing when it happens. The errors that MSN Messenger will raise are defined in an constant enum MSGRConstants, this enum disappeared in MSN Messenger 6, so download our export of it instead. Because this export is from MSN Messenger 5, it is now missing new values introduced in MSN Messenger 6 and 7. It is also renamed MSNMSGRConstants for compatibility purposes.
This example handles two common errors when calling AutoSignin, one being if the sign in details aren’t saved (”remember sign-in name and passport..”), and if the user is already signed in.
Option Explicit Public m_objMessenger As MessengerAPI.Messenger Private Sub Form_Load() Dim eError As MSNMSGRConstants On Error GoTo ErrForm_Load Set m_objMessenger = New MessengerAPI.Messenger Call m_objMessenger.AutoSignin ErrForm_Load: eError = Err.Number If eError = MSGR_E_FAIL Then Debug.Print "Signin name and password are not saved." ElseIf eError = MSGR_E_ALREADY_LOGGED_ON Then Debug.Print "Already logged in." End If End Sub
What happens here is, code execution goes to a special handler when an error occurs, a MSNMSGRConstant enum variable is set to the last error number, Err.Number. And an if statement detects what the error was and prints to debug a little detail.
0 Response to “Error handling”