Convert C# into VB.Net

Hello Everyone,


How can I convert this code into vb.net?

<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="ASPEMAILLib" %>
<%@ Import Namespace="System.Reflection" %>


<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
{
      // Change this to your own SMTP server
      String strHost = "192.168.1.21";      
      
      txtHost.InnerHtml = strHost;      
      
      if( IsPostBack )
      {
            // MailSender object declaration
            ASPEMAILLib.IMailSender objMail;
            objMail = new ASPEMAILLib.MailSender();

            objMail.Host = strHost;

            objMail.From = txtFrom.Value;            // From address
            objMail.FromName = txtFromName.Value;      // optional

            // To address, 2nd argument optional
            objMail.AddAddress(txtTo.Value, Missing.Value);            
            
            // message subject
            objMail.Subject = txtSubject.Value;
            
            // message body
            objMail.Body = txtBody.Value;

            try
            {
                  objMail.Send(Missing.Value);
                  txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>";
            }
            catch(Exception e)
            {
                  txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>";
            }
      }
}

</script>
sonu19Asked:
Who is Participating?
 
VBRocksCommented:
Here you go:

<%@ Imports Namespace="System.Web" %>
<%@ Imports Namespace="ASPEMAILLib" %>
<%@ Imports Namespace="System.Reflection" %>


<script runat="server" LANGUAGE="VB">

Public Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

      'Change this to your own SMTP server
      Dim strHost As String = "192.168.1.21"
     
      txtHost.InnerHtml = strHost
     
      if IsPostBack = True Then

            'MailSender object declaration
            Dim objMail as ASPEMAILLib.IMailSender
            objMail = new ASPEMAILLib.MailSender()

            objMail.Host = strHost

            objMail.From = txtFrom.Value           'From address
            objMail.FromName = txtFromName.Value   ' optional

            'To address, 2nd argument optional
            objMail.AddAddress(txtTo.Value, Missing.Value)
           
            'message subject
            objMail.Subject = txtSubject.Value
           
            'message body
            objMail.Body = txtBody.Value

            try
                  objMail.Send(Missing.Value)
                  txtMsg.InnerHtml = "<font color=green>Success! Message sent to " & txtTo.Value & ".</font>"

            catch e As Exception
                  txtMsg.InnerHtml = "<font color=red>Error occurred: " & e.Message & "</font>"
          end try
      End If
End Sub

</script>

0
 
Wayne Taylor (webtubbs)Commented:
Using http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx....

 Imports System.Web
 Imports ASPEMAILLib
 Imports System.Reflection

 Private Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
     ' Change this to your own SMTP server
     Dim strHost As String = "192.168.1.21"
   
     txtHost.InnerHtml = strHost
   
     If IsPostBack Then
         ' MailSender object declaration
         Dim objMail As ASPEMAILLib.IMailSender
         objMail = New ASPEMAILLib.MailSender()
       
         objMail.Host = strHost
       
         objMail.From = txtFrom.Value
         ' From address
         objMail.FromName = txtFromName.Value
         ' optional
         ' To address, 2nd argument optional
         objMail.AddAddress(txtTo.Value, Missing.Value)
       
         ' message subject
         objMail.Subject = txtSubject.Value
       
         ' message body
         objMail.Body = txtBody.Value
       
         Try
             objMail.Send(Missing.Value)
             txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>"
         Catch e As Exception
             txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>"
         End Try
     End If
 End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.