Results 1 to 7 of 7

Thread: Sending a variable number of arguments to a sub

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Sending a variable number of arguments to a sub

    I am working on an inventory ordering system where I send a different number of email addresses depending on the vendor. I am trying to use one sub to do this instead of the 8 subs it would take if I created one for each vendor.

    I have 1 sub that requires 6 Send addresses, 3 that require 4 Send Addresses and 4 that require 4 Send Addresses. Is it possible to this all with one sub leaving blanks in the arguments so that they are ignored?

    Code:
        Private Sub FireEMail()
            ' The first email has 6 addresses
    
            MightyEmail( _
                "[email protected]", _
                "[email protected]", _
                "[email protected]", _
                "[email protected]", _
                "[email protected]", _
                "[email protected]", _
                "[email protected]", _
                "strSubject", "strBody", "strPath")
    
            ' The second email has 4 addresses
    
            MightyEmail( _
                "[email protected]", _
                "strTo1Somewhereelse.com", _
                "StrTo2Somewhereelse.com", _
                "StrTo3Somewhereelse.com", _
                "strSubject", "strBody", "strPath")
            ' The fourth has 4 etc..
    
        End Sub
    
        Private Sub MightyEmail( _
            ByVal StrMailFrom As String, _
            ByVal strMailTo1 As String, _
            ByVal strMailTo2 As String, _
            ByVal strMailTo3 As String, _
            ByVal strMailTo4 As String, _
            ByVal strMailTo5 As String, _
            ByVal strmailTo6 As String, _
            ByVal StrSubject As String, _
            ByVal StrBody As String, _
            ByVal strFPath As String)
    
            Dim message As New MailMessage
            message.From = New MailAddress(StrMailFrom)
            message.To.Add(strMailTo1)
            message.To.Add(strMailTo2)
            message.To.Add(strMailTo3)
            message.To.Add(strMailTo4)
            message.To.Add(strMailTo5)
            message.To.Add(strmailTo6)
            message.Subject = StrSubject
            message.Body = StrBody
    
            Dim emailClient As New SmtpClient(strMailServer)
            emailClient.Credentials = (SMTP_Cred)
            emailClient.DeliveryMethod = SmtpDeliveryMethod.Network
            emailClient.EnableSsl = True
            Try
                emailClient.Send(message)
                MessageBox.Show("done")
            Catch ex As Exception
                MessageBox.Show(ex.Message & vbNewLine & ex.StackTrace)
            Finally
    
            End Try
        End Sub
    Last edited by FastEddie; Apr 17th, 2007 at 08:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width