[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Convert C# into VB.Net

Posted on 2007-10-12
Medium Priority
Last Modified: 2013-11-26
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 = "";      
      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;

                  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>";

Question by:sonu19
LVL 27

Accepted Solution

VBRocks earned 2000 total points
ID: 20065691
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 = ""
      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

                  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


LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 20065707
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 = ""
     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
             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

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question