mCore™ .NET SMS Library 1.2

Inbox.Message(i).Delete Method

Description:

The Delete method deletes the particular message from the Inbox as well as the GSM Modem/Phone memory. Returns a Boolean value True if the deletion was successful. If not, it returns a Boolean value False.

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

Exceptions:

mCore.SMSReadException
mCore.SMSDeleteException
mCore.GeneralException

Remarks:

Usage Example:

Visual Basic

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

         Catch ex As mCore.SMSReadException
            MsgBox("Error reading Inbox!" & vbCrLf & ex.Message)
         End Try

         If objSMS.Inbox.HasMessages Then
            MsgBox("Total " & objSMS.Inbox.Count.ToString() & " messages")
            For Each Msg In objSMS.Inbox
               MsgBox(Msg.TimeStampRFC & vbCrLf & Msg.Text, _
                  "From: " & Msg.Phone & "[SMSC: " & Msg.SMSC & "]")
            Next

            'The following loop is same as objSMS.Inbox.Clear()
            For i = objSMS.Inbox.Count To 1 Step -1
               Try
                  objSMS.Inbox.Message(i).Delete
               Catch ex As mCore.SMSDeleteException
                  MsgBox(ex.Message, MsgBoxStyle.Critical, "mCore Demo")
               End Try
            Next
         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.SMS.EnumMessageMemory.ME;
         try
         {
            objSMS.Inbox().Refresh();
         }
         catch (mCore.SMSReadException ex)
         {
            MessageBox.Show("Error reading Inbox!" + "\r\n" + ex.ToString());;
         }
         if (objSMS.Inbox().HasMessages)
         {
            MessageBox.Show("Total " + objSMS.Inbox().Count.ToString() + " messages");
            foreach (mCore.Message Msg in objSMS.Inbox())
            {
               MessageBox.Show("From: " + Msg.Phone +
                  "[SMSC: " + Msg.SMSC + "]\r\n" + Msg.TimeStampRFC +
                  "\r\n" + Msg.Text);
            }

            //The following loop is same as objSMS.Inbox().Clear()
            for (int i = objSMS.Inbox().Count; i >= 1; --i)
            {
               try
               {
                  objSMS.Inbox().Message(i).Delete();
               }
               catch (mCore.SMSDeleteException ex)
               {
                  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:

Inbox.Message(i) Method
Inbox.Clear Method

 

Copyright © IG Logix Softech Pvt Ltd, All Rights Reserved