Question Passing string.text fields to use in module file

graham23s

Member
Joined
Feb 22, 2009
Messages
13
Programming Experience
1-3
Hi Guys,

I have been coding a small program to login to pop servers using IMAP, my very basic code is:

VB.NET:
Imports System.IO
Imports System.Net.Sockets
Imports System.Text
Imports System.Net.Security
Imports System.Net
Imports Limilabs.Mail
Imports Limilabs.Client.IMAP

Public Class formMain

    Private Sub mainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles getMailButton.Click

        '// On Get Emails button, do some validation of the fields before processing...

    End Sub

End Class

I have added the reference to the mail.dll from an example here: Windows Download emails using IMAP sample in C#, VB.NET

The module file:

VB.NET:
Imports Limilabs.Mail
Imports Limilabs.Client.IMAP

Public Module Module1
    Public Sub Main(ByVal args As String())
        Using imap As New Imap()
            imap.Connect("pop.aol.com")   ' or ConnectSSL for SSL 
            imap.Login("user", "password")

            imap.SelectInbox()
            Dim uids As List(Of Long) = imap.Search(Flag.Unseen)

            For Each uid As Long In uids
                Dim eml As String = imap.GetMessageByUID(uid)
                Dim email As IMail = New MailBuilder() _
                    .CreateFromEml(eml)

                Console.WriteLine(email.Subject)
                Console.WriteLine(email.Text)
            Next
            imap.Close()
        End Using
    End Sub
End Module

The bit i'm having trouble with is passing my form variables:

strServer.text
strUser.text
strPass.text

to the module file to use:

imap.Connect(strServer.text) ' or ConnectSSL for SSL
imap.Login(strUser.text, strPass.text)

I have spent to long away from coding, just getting the feel for it again :)

thanks for any help guys

Graham
 
Presumably you got that module from a code example for a Console app. Get rid of the module and put the code to retrieve the email in a method in your form. Then there's obviously no issue using form controls for the data.

If you want to use that module then get rid of the Main method and write your own method with an appropriate name and with appropriate parameters. You then call the method and pass the data from your controls to the parameters.
 
Back
Top