mCore™ .NET SMS Library 1.2

Inbox.Message Method

Description:

The Inbox.Message method returns a message item from the Inbox as a mCore.Message class object. Each message item is read using a Integer index passed as a parameter.

Namespace: mCore
Assembly: mCoreLib (in mCoreLib.dll)

Remarks:

To read a message at index position i, Inbox.Message(i) method would return the same result as mCore.SMS.Inbox(i) method

Exceptions:

mCore.SMSReadException
mCore.GeneralException

Usage Example:

Visual Basic

Public Class MyClass
   Public WithEvents objSMS As New mCore.SMS
   Public Sub ReadInbox()
      Msg As mCore.Message
      Try
         SetCommParameters()
         objSMS.MessageMemory = mCore.MessageMemory.ME
         Try
            objSMS.Inbox.Refresh()

            If objSMS.Inbox.HasMessages Then
               MsgBox("Total " & objSMS.Inbox.Count.ToString() & " messages")
               For i = 1 To objSMS.Inbox.Count
                  Msg = objSMS.Inbox.Message(i)
                  'objSMS.Inbox(i) is same as objSMS.Inbox.Message(i)
                  MsgBox("From:" & Msg.Phone & vbCrLf & Msg.Text)
               Next
            End If
         Catch ex As mCore.SMSReadException
            MsgBox("Error reading Inbox!" & vbCrLf & ex.Message)
         End Try

         If objSMS.Inbox.HasMessages Then
            Try
               objSMS.Inbox.Clear()
            Catch ex As mCore.SMSDeleteException
               MsgBox(ex.Message, MsgBoxStyle.Critical, "mCore Demo")
            End Try
         End If

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message, MsgBoxStyle.Critical, "mCore Demo")
      Catch ex As Exception
      End Try
   End Sub

   Public Sub SetCommParameters()
      Try
         objSMS.Port = "COM1"
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200
         objSMS.DataBits = mCore.DataBits.Eight
         objSMS.StopBits = mCore.StopBits.One
         objSMS.Parity = mCore.Parity.None
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message)
      Catch ex As Exception
      End Try
   End Function
End Class

 
C#
class MyClass
{
   public mCore.SMS objSMS = new mCore.SMS();
   public static void ReadInbox()
   {
      mCore.Message Msg;
      try
      {

         SetCommParameters();
         objSMS.MessageMemory = mCore.MessageMemory.ME;
         try
         {
            objSMS.Inbox().Refresh();
            if (objSMS.Inbox().HasMessages)
            {
               MessageBox.Show("Total " + objSMS.Inbox().Count.ToString() + " messages");
               for (int i = 1; i <= objSMS.Inbox().Count; i++)
               {
                  Msg = objSMS.Inbox().Message(i)
                  //objSMS.Inbox(i) is same as objSMS.Inbox.Message(i)
                  MessageBox.Show("From: " + Msg.Phone + "\r\n" + Msg.Text);
               }
            }
         }
         catch (mCore.SMSReadException ex)
         {
            MessageBox.Show("Error reading Inbox!" + "\r\n" + ex.ToString());;
         }

         if (objSMS.Inbox().HasMessages)
         {
            try
            {
               objSMS.Inbox().Clear();
            }
            catch (mCore.SMSDeleteException e)
            {
               MessageBox.Show(e.ToString());
            }
         }
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }

   public static void SetCommParameters()
   {
      try
      {
         objSMS.Port = "COM1";
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200;
         objSMS.DataBits = mCore.DataBits.Eight;
         objSMS.StopBits = mCore.StopBits.One;
         objSMS.Parity = mCore.Parity.None;
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS;
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }
}

See Also:

mCore.SMS.Inbox Method
Inbox.Refresh Method
mCore.SMSReadException Class

 

Copyright © IG Logix Softech Pvt Ltd, All Rights Reserved