将单选按钮参数传递给 vb.net 中的另一个函数

发布于 2024-12-13 02:57:23 字数 2883 浏览 1 评论 0原文

我有两个函数,一个是 SaveData(),另一个是

SaveData() 中的 SendEmail(),保存所选的单选按钮,最后调用 SendMail()。

在 SendMail() 中,单选按钮被“测试”,然后根据单选选项发送两封电子邮件之一。

我遇到的问题是正确传递参数。我尝试了几种不同的方法,但参数没有发送到 SendMail()

单选按钮是/否问题

对于为什么参数没有被传递有什么想法吗?

这是我所拥有的:

Protected Function SaveData()
...
Q1 = Me.rblnewqst1.SelectedValue
        Q2 = Me.rblnewqst2.SelectedValue
        Q3 = Me.rblnewqst3.SelectedValue
        Q4 = Me.rblnewqst4.SelectedValue
        Q5 = Me.rblnewqst5.SelectedValue

....

SendEmail() 是

Protected Sub SendEmail(ByVal rblnewqst1 As Object, ByVal rblnewqst2 As Object, ByVal rblnewqst3 As Object, ByVal rblnewqst4 As Object, ByVal rblnewqst5 As Object)

    If rblnewqst1.SelectedValue = 2 Or rblnewqst2.SelectedValue = 2 Or rblnewqst3.SelectedValue = 2 Or rblnewqst4.SelectedValue = 2 Or rblnewqst5.SelectedValue = 2 Then

        Dim sResponseFromName As String = "[email protected]"
        Dim sResponseToName As String = txtEmail.Text
        Dim sResponseSubject As String = "Denied"
        Dim sResponseBody As String = "Message>"


        Try
            Dim mm As New MailMessage(sResponseFromName, sResponseToName)
            Dim SMTP As New SmtpClient

            SMTP.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

            mm.Subject = sResponseSubject
            mm.Body = sResponseBody
            mm.IsBodyHtml = True

            Try

                SMTP.Send(mm)

            Catch exSmtpException As SmtpException
                Dim stemp As String = exSmtpException.Message.ToString
            End Try

        Catch ex As ApplicationException
            Dim stemp As String = ex.InnerException.Message.ToString
        End Try

    Else
        Dim sResponseFromName As String = "[email protected]"
        Dim sResponseToName As String = txtEmail.Text
        Dim sResponseSubject As String = "Accepted"
        Dim sResponseBody As String = "MESSAGE....."

        Try
            Dim mm As New MailMessage(sResponseFromName, sResponseToName)
            Dim SMTP As New SmtpClient

            SMTP.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

            mm.Subject = sResponseSubject
            mm.Body = sResponseBody
            mm.IsBodyHtml = True

            Try

                SMTP.Send(mm)

            Catch exSmtpException As SmtpException
                Dim stemp As String = exSmtpException.Message.ToString
            End Try

        Catch ex As ApplicationException
            Dim stemp As String = ex.InnerException.Message.ToString
        End Try
    End If

End Sub

I have 2 functions, one is SaveData() and the other is SendEmail()

in the SaveData() the radio buttons that are selected are saved, and the SendMail() is called at the end.

in the SendMail() the radio buttons are "tested" and then one of two emails is sent out based on the radio choices.

The problem I am having is passing the parameters correctly. I have tried several different method but the parameters are not being sent to SendMail()

The radio buttons are Yes/No questions

Any thoughts on why the parameters are not being passed?

Here is what I have:

Protected Function SaveData()
...
Q1 = Me.rblnewqst1.SelectedValue
        Q2 = Me.rblnewqst2.SelectedValue
        Q3 = Me.rblnewqst3.SelectedValue
        Q4 = Me.rblnewqst4.SelectedValue
        Q5 = Me.rblnewqst5.SelectedValue

....

and the SendEmail() is

Protected Sub SendEmail(ByVal rblnewqst1 As Object, ByVal rblnewqst2 As Object, ByVal rblnewqst3 As Object, ByVal rblnewqst4 As Object, ByVal rblnewqst5 As Object)

    If rblnewqst1.SelectedValue = 2 Or rblnewqst2.SelectedValue = 2 Or rblnewqst3.SelectedValue = 2 Or rblnewqst4.SelectedValue = 2 Or rblnewqst5.SelectedValue = 2 Then

        Dim sResponseFromName As String = "[email protected]"
        Dim sResponseToName As String = txtEmail.Text
        Dim sResponseSubject As String = "Denied"
        Dim sResponseBody As String = "Message>"


        Try
            Dim mm As New MailMessage(sResponseFromName, sResponseToName)
            Dim SMTP As New SmtpClient

            SMTP.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

            mm.Subject = sResponseSubject
            mm.Body = sResponseBody
            mm.IsBodyHtml = True

            Try

                SMTP.Send(mm)

            Catch exSmtpException As SmtpException
                Dim stemp As String = exSmtpException.Message.ToString
            End Try

        Catch ex As ApplicationException
            Dim stemp As String = ex.InnerException.Message.ToString
        End Try

    Else
        Dim sResponseFromName As String = "[email protected]"
        Dim sResponseToName As String = txtEmail.Text
        Dim sResponseSubject As String = "Accepted"
        Dim sResponseBody As String = "MESSAGE....."

        Try
            Dim mm As New MailMessage(sResponseFromName, sResponseToName)
            Dim SMTP As New SmtpClient

            SMTP.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis

            mm.Subject = sResponseSubject
            mm.Body = sResponseBody
            mm.IsBodyHtml = True

            Try

                SMTP.Send(mm)

            Catch exSmtpException As SmtpException
                Dim stemp As String = exSmtpException.Message.ToString
            End Try

        Catch ex As ApplicationException
            Dim stemp As String = ex.InnerException.Message.ToString
        End Try
    End If

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆里有你的影子 2024-12-20 02:57:23

就像他在评论中提到的 HardCode 一样,我建议您始终使用 Option Explicit 和 Option Strict 。

我要做的第一件事是改变 SendMail 部分的工作方式,从单选按钮中获取值。您的 If 正在检查整数值,因此我将使用 Integer 作为类型。

所以更像是:

Protected Sub SendEmail(ByVal q1 As Integer, ByVal q2 As Integer)

If q1 = 2 Or q2 = 2 Then
etc...
End IF

我缩短了列表,这样我就不必输入太多内容。一般来说,我认为发送值比发送整个对象是更好的做法,除非您出于特定原因需要整个控件。另外,除非您别无选择,否则我不建议您发送对象。

为了测试它,我建议的另一件事是在 sendEmail Sub 内部设置一个断点,使用快速监视来查看发送到您正在检查的方法的实际对象/类型是什么。

Like HardCode mentioned in his comments, I do recommend you always work with Option Explicit and Option Strict on.

The first thing I would do is alter the way the SendMail part works, to take the values from the radio buttons. Your If is checking against and integer value, so I would use Integer as the type.

So something more like:

Protected Sub SendEmail(ByVal q1 As Integer, ByVal q2 As Integer)

If q1 = 2 Or q2 = 2 Then
etc...
End IF

I shortened the list so I didn't have to type as much. In general I think it is better practice to send values than entire objects, unless you need the entire control for a specific reason. Also, sending object isn't something I recommend doing unless you have no other choice.

The other thing I would recommend, to test it, is setting a break point just inside the sendEmail Sub, use quick watch to see what the actual objects/types are that are being sent to your method that you are checking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文