Answered by:
help in converting C# to VB.net

Question
-
User719752529 posted
error of occurred EOF expected when converting c# to vb.net
Protected void btnSendPassword_Click(object sender, EventArgs e) { //create your variables string strSubject = "Your Password Has Been Reset"; string strFromEmail = "me@mywebsite.com"; string strFromName = "My Website Administrator"; string strNewPassword = GeneratePassword().ToString(); //This is where you'd call the new password string. try { //create the new mail message[/color] MailMessage MailMsg = new MailMessage(); //cretate the FROM[/color] MailMsg.From = new MailAddress(strFromEmail); //create the subject[/color] MailMsg.Subject = strSubject; //We obviously need to create the TO - otherwise it goes nowhere. MailMsg.To.Add(txtEmail.Text); //assuming there was a form to fill out and they put the right email address in. MailMsg.IsBodyHtml = true; //I decided to make it html - so I could format the text. MailMsg.Body = "<h1>The following email was sent to you by " + strFromName + ".</h1><br />"; MailMsg.Body += "<p>Apparently, you needed your password reset - So here it is: <br />"; MailMsg.Body += "New Password <b>" + strNewPassword + "</b><br />"; MailMsg.Body += "If you didn't request this, then - oops, you might wanna think about changing it, now. "</b>"; MailMsg.Body += "<p>Click the following link to change your password:</p>"; MailMsg.Body += "<p>http://www.mywebsite.com/passwordChangeThing/Default.aspx</P>"; //utilizing SMTP (simple mail transfer protocol) SmtpClient smtp = new SmtpClient(); smtp.Host = "email.mywebsite.com"; //if my domain had a way of sending out emails. smtp.Send(MailMsg); //send it lblMessage.Text = "Message Sent Successfully"; //tell the person that the email was sent. } catch (Exception ex) { lblMessage.Text = "Error: " + ex.ToString(); //or tell the person that they screwed up and it's all their fault.... or what the actual error was. } }
Monday, January 16, 2012 11:55 PM
Answers
-
User-68639941 posted
you have missed out + operator in below line
MailMsg.Body +="If you didn't request this, then - oops, you might wanna think about changing it, now." + "</b>";
Refer Below Converted Code :
Protected Sub btnSendPassword_Click(sender As Object, e As EventArgs) 'create your variables Dim strSubject As String = "Your Password Has Been Reset" Dim strFromEmail As String = "me@mywebsite.com" Dim strFromName As String = "My Website Administrator" Dim strNewPassword As String = GeneratePassword().ToString() 'This is where you'd call the new password string. Try 'create the new mail message[/color] Dim MailMsg As New MailMessage() 'cretate the FROM[/color] MailMsg.From = New MailAddress(strFromEmail) 'create the subject[/color] MailMsg.Subject = strSubject 'We obviously need to create the TO - otherwise it goes nowhere. MailMsg.[To].Add(txtEmail.Text) 'assuming there was a form to fill out and they put the right email address in. MailMsg.IsBodyHtml = True 'I decided to make it html - so I could format the text. MailMsg.Body = "<h1>The following email was sent to you by " + strFromName + ".</h1><br />" MailMsg.Body += "<p>Apparently, you needed your password reset - So here it is: <br />" MailMsg.Body += "New Password <b>" + strNewPassword + "</b><br />" MailMsg.Body += "If you didn't request this, then - oops, you might wanna think about changing it, now." + "</b>" MailMsg.Body += "<p>Click the following link to change your password:</p>" MailMsg.Body += "<p>http://www.mywebsite.com/passwordChangeThing/Default.aspx</P>" 'utilizing SMTP (simple mail transfer protocol) Dim smtp As New SmtpClient() smtp.Host = "email.mywebsite.com" 'if my domain had a way of sending out emails. smtp.Send(MailMsg) 'send it 'tell the person that the email was sent. lblMessage.Text = "Message Sent Successfully" Catch ex As Exception 'or tell the person that they screwed up and it's all their fault.... or what the actual error was. lblMessage.Text = "Error: " + ex.ToString() End Try End Sub
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, January 17, 2012 12:08 AM
All replies
-
User197322208 posted
string strSubject = "Your Password Has Been Reset";This is C#
What is the VB.NET version?
Tuesday, January 17, 2012 12:06 AM -
User-68639941 posted
you have missed out + operator in below line
MailMsg.Body +="If you didn't request this, then - oops, you might wanna think about changing it, now." + "</b>";
Refer Below Converted Code :
Protected Sub btnSendPassword_Click(sender As Object, e As EventArgs) 'create your variables Dim strSubject As String = "Your Password Has Been Reset" Dim strFromEmail As String = "me@mywebsite.com" Dim strFromName As String = "My Website Administrator" Dim strNewPassword As String = GeneratePassword().ToString() 'This is where you'd call the new password string. Try 'create the new mail message[/color] Dim MailMsg As New MailMessage() 'cretate the FROM[/color] MailMsg.From = New MailAddress(strFromEmail) 'create the subject[/color] MailMsg.Subject = strSubject 'We obviously need to create the TO - otherwise it goes nowhere. MailMsg.[To].Add(txtEmail.Text) 'assuming there was a form to fill out and they put the right email address in. MailMsg.IsBodyHtml = True 'I decided to make it html - so I could format the text. MailMsg.Body = "<h1>The following email was sent to you by " + strFromName + ".</h1><br />" MailMsg.Body += "<p>Apparently, you needed your password reset - So here it is: <br />" MailMsg.Body += "New Password <b>" + strNewPassword + "</b><br />" MailMsg.Body += "If you didn't request this, then - oops, you might wanna think about changing it, now." + "</b>" MailMsg.Body += "<p>Click the following link to change your password:</p>" MailMsg.Body += "<p>http://www.mywebsite.com/passwordChangeThing/Default.aspx</P>" 'utilizing SMTP (simple mail transfer protocol) Dim smtp As New SmtpClient() smtp.Host = "email.mywebsite.com" 'if my domain had a way of sending out emails. smtp.Send(MailMsg) 'send it 'tell the person that the email was sent. lblMessage.Text = "Message Sent Successfully" Catch ex As Exception 'or tell the person that they screwed up and it's all their fault.... or what the actual error was. lblMessage.Text = "Error: " + ex.ToString() End Try End Sub
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, January 17, 2012 12:08 AM -
User1594247892 posted
http://www.developerfusion.com/tools/convert/vb-to-csharp/
Tuesday, January 17, 2012 12:10 AM -
User1643008609 posted
Hi Friend,
I have used http://www.dotnetspider.com/convert/CSharp-To-Vb.aspx to convert the code , following are the converted code.Protected Sub btnSendPassword_Click(ByVal sender As Object, ByVal e As EventArgs) 'create your variables Dim strSubject As String = "Your Password Has Been Reset" Dim strFromEmail As String = "me@mywebsite.com" Dim strFromName As String = "My Website Administrator" Dim strNewPassword As String = GeneratePassword().ToString() 'This is where you'd call the new password string. Try 'create the new mail message[/color] Dim MailMsg As MailMessage = New MailMessage() 'cretate the FROM[/color] MailMsg.From = New MailAddress(strFromEmail) 'create the subject[/color] MailMsg.Subject = strSubject 'We obviously need to create the TO - otherwise it goes nowhere. Dim 'assuming there was a form to fill out and they put the right email address in. As MailMsg.To.Add(txtEmail.Text) MailMsg.IsBodyHtml = True 'I decided to make it html - so I could format the text. MailMsg.Body = "<h1>The following email was sent to you by " + strFromName + ".</h1><br />" MailMsg.Body += "<p>Apparently, you needed your password reset - So here it is: <br />" MailMsg.Body += "New Password <b>" + strNewPassword + "</b><br />" MailMsg.Body += "If you didn't request this, then - oops, you might wanna think about changing it, now. </b>" MailMsg.Body += "<p>Click the following link to change your password:</p>" MailMsg.Body += "<p>http://www.mywebsite.com/passwordChangeThing/Default.aspx</P>" 'utilizing SMTP (simple mail transfer protocol) Dim smtp As SmtpClient = New SmtpClient() smtp.Host = "email.mywebsite.com" 'if my domain had a way of sending out emails. Dim 'send it As smtp.Send(MailMsg) lblMessage.Text = "Message Sent Successfully" 'tell the person that the email was sent. Catch ex As Exception lblMessage.Text = "Error: " + ex.ToString() 'or tell the person that they screwed up and it's all their fault.... or what the actual error was. End Try End Sub
Tuesday, January 17, 2012 12:11 AM -
User-1971614856 posted
Protected Sub btnSendPassword_Click(sender As Object, e As EventArgs) 'create your variables Dim strSubject As String = "Your Password Has Been Reset" Dim strFromEmail As String = "me@mywebsite.com" Dim strFromName As String = "My Website Administrator" Dim strNewPassword As String = GeneratePassword().ToString() 'This is where you'd call the new password string. Try 'create the new mail message[/color] Dim MailMsg As New MailMessage() 'cretate the FROM[/color] MailMsg.From = New MailAddress(strFromEmail) 'create the subject[/color] MailMsg.Subject = strSubject 'We obviously need to create the TO - otherwise it goes nowhere. MailMsg.[To].Add(txtEmail.Text) 'assuming there was a form to fill out and they put the right email address in. MailMsg.IsBodyHtml = True 'I decided to make it html - so I could format the text. MailMsg.Body = "<h1>The following email was sent to you by " & strFromName & ".</h1><br />" MailMsg.Body += "<p>Apparently, you needed your password reset - So here it is: <br />" MailMsg.Body += "New Password <b>" & strNewPassword & "</b><br />" MailMsg.Body += "If you didn't request this, then - oops, you might wanna think about changing it, now.</b>" MailMsg.Body += "<p>Click the following link to change your password:</p>" MailMsg.Body += "<p>http://www.mywebsite.com/passwordChangeThing/Default.aspx</P>" 'utilizing SMTP (simple mail transfer protocol) Dim smtp As New SmtpClient() smtp.Host = "email.mywebsite.com" 'if my domain had a way of sending out emails. smtp.Send(MailMsg) 'send it 'tell the person that the email was sent. lblMessage.Text = "Message Sent Successfully" Catch ex As Exception 'or tell the person that they screwed up and it's all their fault.... or what the actual error was. lblMessage.Text = "Error: " & ex.ToString() End Try End Sub
Tuesday, January 17, 2012 12:14 AM -
User139864016 posted
Hello,
Try the link below.
http://www.developerfusion.com/tools/convert/csharp-to-vb/
Tuesday, January 17, 2012 12:32 AM -
User397347636 posted
Karthick is right - the code is not valid C# code.
Converters must assume that the code being converted conforms to the proper language syntax. If not, then the result will be unpredictable.
Once you change the code to be proper C# code, then any converter will convert this sample.
Tuesday, January 17, 2012 10:45 AM -
User497476629 posted
next time, you can use the code convertors one line at a time, or only conver a bunch of lines at a time,
so you can know where exactly is the error,
you can also add the code to the visual studio, and see if it produces a syntax error or not
Thursday, January 26, 2012 2:07 PM -
User828770893 posted
Also try this online free converter:
it gives the good results.
thanks
Wednesday, January 23, 2013 12:28 PM