在VB.NET中使用循环 [英] use loops in VB.NET

查看:77
本文介绍了在VB.NET中使用循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我的项目很小,但我不知道如何使用循环并将电子邮件发送到邮件列表,谁可以帮助我编辑项目

谢谢.

Hi everybody

I have small project but i don''t know how to use loop and send email to mailing list, who can help me edit my project

Thanks.

推荐答案

<pre lang="vb">Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mymailmessage As New MailMessage
        mymailmessage.From = New MailAddress(TextBox1.Text)
        mymailmessage.To.Add(TextBox3.Text)
        mymailmessage.Subject = (TextBox4.Text)
        mymailmessage.Body = (TextBox5.Text)
        Dim smtpserver As New SmtpClient("smtp.gmail.com")
        smtpserver.Port = (587)
        smtpserver.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
        smtpserver.EnableSsl = True
        smtpserver.Send(mymailmessage)
        Label7.Text = Val(Label7.Text + 1)
        On Error Resume Next
        ProgressBar1.PerformStep()
        If ProgressBar1.Value >= ProgressBar1.Maximum Then
            Timer1.Enabled = False
        End If
    End Sub



你好.
首先 Label7.Text = Val(Label7.Text + 1)这似乎不正确,应该像 Label7.Text = Val(Label7.Text)+ 1

其次,将所有这些都放入计时器事件中,您必须意识到,如果这只是运行的一部分代码,并且在运行的代码中的任何地方都需要调用application.doevents,您的计时器将被触发并子可能到那时还没完成.

至于邮件列表,如果您有要发送到的电子邮件地址列表,则可以执行每隔一个".
在这种情况下,就像
Hello.
First of all Label7.Text = Val(Label7.Text + 1) this doesn''t seem right it should be like Label7.Text = Val(Label7.Text) + 1

Secondly, you''ve put all of this in a timer event, you have to realize that if this is just a piece of the code that runs and if anywhere within the running code you call for application.doevents your timer will get fired and the sub may have not finished by that time.

As for the mailing list, you could do For Each Next if you have a list of e-mail adresses you want to send to.
In this case it would be like
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim mymailmessage As New MailMessage
        mymailmessage.From = New MailAddress(TextBox1.Text)
           For Each address_book_record as string in Listbox1.items 'example if you use a listbox to store addresses
            mymailmessage.To.Add(address_book_record)
           Next
        mymailmessage.Subject = (TextBox4.Text)
        mymailmessage.Body = (TextBox5.Text)
        Dim smtpserver As New SmtpClient("smtp.gmail.com")
        smtpserver.Port = (587)
        smtpserver.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text)
        smtpserver.EnableSsl = True
        smtpserver.Send(mymailmessage)
        Label7.Text = Val(Label7.Text) + 1
        On Error Resume Next
        ProgressBar1.PerformStep()
        If ProgressBar1.Value >= ProgressBar1.Maximum Then
            Timer1.Enabled = False
        End If
    End Sub



这会将您的电子邮件发送到列表框1中的所有地址.



This would send your mail message to all the addresses in the listbox1.


这篇关于在VB.NET中使用循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆