?
Solved

Coverting VB into C#

Posted on 2008-11-10
8
Medium Priority
?
548 Views
Last Modified: 2012-05-05
Can anyone recommend some free tools on how convert VB into C#?  I tried using:
http://www.developerfusion.com/tools/convert/vb-to-csharp/
but I get an error that:

    * protected void // ERROR: Handles clauses are not supported in C# rbl1_SelectedIndexChanged(object sender, System.EventArgs e)
    * {
    *    
    *     if (rblAns.SelectedValue == "status_guest") {
    *         RequiredFieldValidator4.enabled = true;
    *     }
    *     else {
    *         RequiredFieldValidator4.enabled = false;
    *     }
    *    
    * }


<SCRIPT LANGUAGE="VBScript"> 
//Give users the option to enter school information
         
  Protected Sub rbl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbl1.SelectedIndexChanged
     
  If rblAns.SelectedValue = "status_guest" Then
      RequiredFieldValidator4.enabled = True
  else
      RequiredFieldValidator4.enabled = False
  End If
 
End Sub
 
 
 </script>

Open in new window

0
Comment
Question by:jianxin9
8 Comments
 
LVL 14

Expert Comment

by:Daniel Junges
ID: 22924074
you can use SharpDevelop, it is free
http://www.icsharpcode.net/OpenSource/SD/
0
 
LVL 12

Expert Comment

by:jandromeda
ID: 22924078
I'm not sure there is any too which converts the 'Handles' clause to the C#. But you can fix this without the help of a tool. Try this code.
protected void rbl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
   
   if (rblAns.SelectedValue == "status_guest") {
        RequiredFieldValidator4.enabled = true;
   }
    else {
         RequiredFieldValidator4.enabled = false;
   }
    
 }
 
// and at the place where you declared and initialized the rbl1 add this code.
 <asp:RadioButtonList id="rbl1" 
            OnSelectedIndexChanged="rbl1_SelectedIndexChanged"
            AutoPostBack="true"
            runat="server"/>

Open in new window

0
 

Author Comment

by:jianxin9
ID: 22924157
Thanks for posting!  Okay, when I try this I am getting a runtime error. I have posted the code I am using below.  Thanks!

Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>
<script runat="server" language="C#">
protected void status_SelectedIndexChanged(object sender, System.EventArgs e)
{
   
   if (rblAns.SelectedValue == "status_guest") {
        RequiredFieldValidator4.enabled = true;
   }
    else {
         RequiredFieldValidator4.enabled = false;
   }
    
 }
 
 
 
 </script>
 
 
 
RADIO BUTTON LIST:
Status:*<br /><asp:RadioButtonList id="status" 
            OnSelectedIndexChanged="status_SelectedIndexChanged"
            AutoPostBack="true"
            runat="server"/>
 
                                <asp:ListItem id="status_undergrad" runat="server" Value="undergraduate" />
                                <asp:ListItem id="status_grad" runat="server" Value="graduate" />
                                <asp:ListItem id="status_fs" runat="server" Value="faculty or staff" />
                                 <asp:ListItem id="status_guest" runat="server" Value="guest user (non)" /></asp:RadioButtonList>   
 
                                                                                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="status"
                            ErrorMessage="Status" runat="Server" Text="*Status Required"></asp:RequiredFieldValidator><br />
                                                                                                                If you are a guest user, <br /> please tell us what school are you from:<asp:TextBox ID="school" runat="server"></asp:TextBox>
 <asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="school"
                            ErrorMessage="School Name" runat="Server" Text="*School Name Required"></asp:RequiredFieldValidator>
           
        <br />

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:jandromeda
ID: 22924571
This is firing because it cannot capture another error. So as the first step add this to the web.config of your application. If you already have a '<system.web>' element add the '<customErrors mode = "Off"/>' into that.

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
0
 

Author Comment

by:jianxin9
ID: 22924721
Hi, thanks for posting.  I do currently have this in my web.config and I'm still getting the error.  I am going to post all my code behind--I don't expect you to go through it all, of course, but maybe something might stand out?


<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
<%@ Page Language="c#" Debug="true" %>
 
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
 
<script runat="server" language="C#">
		 
 
 
  void Page_Load()
  {
      if (Page.IsPostBack)
      {
          questionsPanel.Visible = false;
          Message.Visible = true;  
          int correct = 0;
          if (q1.SelectedIndex == 2) correct++;
          if (q2.SelectedIndex == 4) correct++;
          if (q3.SelectedIndex == 2) correct++;
          if (q4.SelectedIndex == 0) correct++;
          if (q5.SelectedIndex == 5) correct++;
          if (q6.SelectedIndex == 1) correct++;
          if (q7.SelectedIndex == 2) correct++;
 
          LoadConn(correct);
      }
      else
      {
          questionsPanel.Visible = true;
          Message.Visible = false;  
      }
  }
 
private void LoadConn(int score)
{
    int percent;
    percent = (score*100)/7;  
  
    // Create the objects 
    OleDbConnection conn;
    OleDbCommand comm;
    
    // Instance the connection open it
    conn = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source ="+ Server.MapPath("assessments.accdb")+";User Id=Admin; Jet OLEDB:Database Password=Live4Ever;");
    conn.Open();
    
    // Create the insert SQL 
    string sSQL = "";
		string qname = "plagiarism"; 
    sSQL = "Insert into posttest_table(fname,lname,username,coursenum,emailId,emailId2,status,school,qname,answered,score,q1,q2,q3,q4,q5,q6,q7) values('" + fname.Text + "','" + lname.Text +"','" + portal_id.Text +"','"+course_id.Text+"','"+emailId.Text+"','"+emailId2.Text+"','"+(status.SelectedIndex+1)+"','"+ school.Text +"','"+(qname)+"',"+score+","+percent+","+(q1.SelectedIndex+1)+","+(q2.SelectedIndex+1)+","+(q3.SelectedIndex+1)+","+(q4.SelectedIndex+1)+","+(q5.SelectedIndex+1)+","+(q6.SelectedIndex+1)+","+(q7.SelectedIndex+1)+");";
   
    //  Response.Write(sSQL + "<br />");
    //  Response.End();
    //  return;
    
    // Create a command object from the connection
    comm = conn.CreateCommand ();
    comm.CommandText = sSQL;
    comm.CommandType = CommandType.Text;
 
    // Try the insert 
    try
    {
        comm.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        Response.Write("Error During DB Update: " + ex.ToString());
    }
    
    
   
    conn.Close();
    // Inserting data into the database end
     
    // Create the email body text
/* String bodyInfo = fname.Text+" "+lname.Text+" has taken the exam.\n <br />"+fname.Text  +" has scored: "+percent+" out of 100 and gotten "+score+" out of 7 questions correct.\n<br /><br />"+fname.Text  +"'s options were: \n<br /> Question 1. Plagiarism is the act of: <br />The correct answer is: using someone else's work and not giving them credit (Option 3)<br /> You Answered:  Option "+(q1.SelectedIndex+1)+"\n <br /><br />Question 2.  Which of the following is copyrighted infringement? <br />The correct answer is: all of the above (Option 5) <br />You Answered: Option "+(q2.SelectedIndex+1)+"\n <br /><br />Question 3.  Accidental plagiarism is: <br />The correct answer is: always unacceptable (Option 3) <br />You Answered: Option "+(q3.SelectedIndex+1)+"\n <br /><br />Question 4. When citing my resources it is important that I: <br />The correct answer is: use a standard citation format assigned by your professor (Option 1) <br />You Answered: Option "+(q4.SelectedIndex+1)+"\n <br /><br />Question 5. RefWorks can help you: <br />The correct answer is: a, c, d (Option 6) <br />You Answered: Option "+(q5.SelectedIndex+1)+"\n<br /><br /> Question 6. Which of the following best describes plagiarism?  <br />The correct answer is: It's a serious offense and can result in severe penalties (Option 2) <br />You Answered: Option "+(q6.SelectedIndex+1)+"\n<br /><br /> Question 7. When do you have to cite your resources? <br /> The correct answer is: when what you are writing about is someone else's idea (Option 3) <br /> You Answered: Option "+(q7.SelectedIndex+1);*/
 
 String bodyInfo = fname.Text+" "+lname.Text+" is a/an "+status.Text+", and has taken the exam for the course "+course_id.Text+".\n <br />"+fname.Text+" has scored: "+percent+" out of 100 and gotten "+score+" out of 7 questions correct.\n<br /><br />"+fname.Text  +"'s options were: \n<br /> Question 1. Plagiarism is the act of: <br />The correct answer is: using someone else's work and not giving them credit (Option c)<br /> You Answered:  Option "+Convert.ToChar(q1.SelectedIndex+97)+"\n <br /><br />Question 2.  Which of the following is copyrighted infringement? <br />The correct answer is: all of the above (Option e) <br />You Answered: Option "+Convert.ToChar(q2.SelectedIndex+97)+"\n <br /><br />Question 3.  Accidental plagiarism is: <br />The correct answer is: always unacceptable (Option c) <br />You Answered: Option "+Convert.ToChar(q3.SelectedIndex+97)+"\n <br /><br />Question 4. When citing my resources it is important that I: <br />The correct answer is: use a standard citation format assigned by your professor (Option a) <br />You Answered: Option "+Convert.ToChar(q4.SelectedIndex+97)+"\n <br /><br />Question 5. RefWorks can help you: <br />The correct answer is: a, c, d (Option f) <br />You Answered: Option "+Convert.ToChar(q5.SelectedIndex+97)+"\n<br /><br /> Question 6. Which of the following best describes plagiarism?  <br />The correct answer is: It's a serious offense and can result in severe penalties (Option b) <br />You Answered: Option "+Convert.ToChar(q6.SelectedIndex+97)+"\n<br /><br /> Question 7. When do you have to cite your resources? <br /> The correct answer is: when what you are writing about is someone else's idea (Option c) <br /> You Answered: Option "+Convert.ToChar(q7.SelectedIndex+97);
 
 
    // Create SMTP client
    SmtpClient client = new SmtpClient("mail.twu.edu");
        
    // Create SMTP message
    MailMessage message = new MailMessage();
 
    // Set message properties 
    message.From = new MailAddress ("automailer@twu.edu");
    message.To.Add("tutorial-results@mail.twu.edu");
    message.CC.Add(emailId.Text);
   if (!string.IsNullOrEmpty(emailId2.Text))
    {
       message.CC.Add(emailId2.Text);
    }
    message.Body = bodyInfo;
    message.Subject = "Doing Research: Plagiarism Quiz Results";
    message.IsBodyHtml = true;
   
    try
        {
 
            // Send EMail
            client.Send(message);
        }
        catch (Exception ex)
        {
            // Do Nothing  
        }
				
 
    // Send the user to the Results page
    Response.Redirect("results.aspx?fname="+fname.Text+"&lname="+lname.Text+"&score="+percent+"&q1="+(q1.SelectedIndex)+"&q2="+(q2.SelectedIndex)+"&q3="+(q3.SelectedIndex)+"&q4="+(q4.SelectedIndex)+"&q5="+(q5.SelectedIndex)+"&q6="+(q6.SelectedIndex)+"&q7="+(q7.SelectedIndex));
 
}
 
protected void status_SelectedIndexChanged(object sender, System.EventArgs e)
{
   
   if (rblAns.SelectedValue == "status_guest") {
        RequiredFieldValidator4.enabled = true;
   }
    else {
         RequiredFieldValidator4.enabled = false;
   }
    
 }
 
 
 
 </script>
 
   

Open in new window

0
 
LVL 12

Accepted Solution

by:
jandromeda earned 1600 total points
ID: 22925316
Modify the Page directive as given below.

<%@ Page Language="c#" Debug="true" AutoEventWireup="true" %>
0
 

Author Comment

by:jianxin9
ID: 22925952
THanks for responding.  Ugh--I am getting the same error.  

Server Error in '/' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>


Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<!-- Web.Config Configuration File -->

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>
0
 
LVL 14

Assisted Solution

by:CyrexCore2k
CyrexCore2k earned 400 total points
ID: 22926634
jian do you have a database that you can access?

I always have trouble getting errors to show up in the browser so I've basically given up on it. However, you can add the Global.asax file to your project and in it's code behind under the Application_Error event just have it save the last error to the database. From there you can just read what the error is in the database.

Here's an example:

       
protected void Application_Error(object sender, EventArgs e)
{
   Exception ex = Server.GetLastError().GetBaseException();
 
   // Connect to database and save ex.ToString() to it. 
            
}

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 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