Kevin Davis

Kevin Davis

  • NA
  • 52
  • 51.2k

Using constructors and accessing data

Aug 7 2011 12:27 PM

Hello everyone,

This is my first post so I apologize firstly if this isn't the  right area to be asking for help.  I have a constructor and an object from that constructor.

1)  Dim formView As FormViewMsg = New FormViewMsg(msg)
       formView.ShowDialog()

new form opens with this:

1) Public Sub New(ByVal msg As MailMessage)
        'This call is required by the Windows Form Designer.
        InitializeComponent()

        ' For HTML message, display plain-text version,
        ' for plain-text message, display the plain-text itself.
        ' HtmlToPlainMode needs to be set BEFORE we access message fields
        ' (body, headers, attachments, etc) because the message gets parsed
        ' when we access any of its parts first time, and HTML to plain-text
        ' conversion takes place during parsing. Thus, we need to tell MailBee that
        ' we wish to get plain-text version of HTML-only mail BEFORE parsing occurs.
        msg.Parser.HtmlToPlainMode = HtmlToPlainAutoConvert.IfNoPlain

        ' Display message headers.
        textboxUID.Text = msg.UidOnServer
        textBoxFrom.Text = msg.From.AsString
        textBoxTo.Text = msg.To.AsString
        textBoxSubject.Text = msg.Subject

        ' Display plain-text body.
        textBoxBody.Text = msg.BodyPlainText

        ' Display attachments.
        textBoxAttachments.Text = String.Empty

        ' Display filenames of the attachments
        Dim attach As Attachment
        For Each attach In msg.Attachments
            ' Show unique file name of the attachment.
            textBoxAttachments.Text &= attach.Filename & "; "
        Next
        'msg.Attachments.SaveAll("C:\Temp", False)
End Sub

3) I am trying to access the "msg" from the sub in a click event of a button, such as this:

Private Sub btnSaveAttachments_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveAttachments.Click


  msg.Attachments.SaveAll("C:\Temp", False)

<----------------------msg, is underlined in red with error " msg is not declared, it may be unaccessible due to it's protection level."
End sub

4) However. I have NO IDEA how to access the information that I need from the "msg".

Sorry if I confused the heck out of everyone.  Now you can see why I am asking for help.  Any help would be very much appreciated.

Thank you.


Answers (2)