Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Please i was following along the Tailspinspywork tutorial on asp.net found on this url http://www.asp.net/web-forms/tutorials/tailspin-spyworks/tailspin-spyworks-part-5[^]. The tutorial is a C# tutorial and i was following along in visual basic cause but i am still a noob at visual basic.net. I used the facilities of developerfusion.com to convert my c# code to vb.net.But the following code is throwing a serious error and i got it from the asp.net tutorial website.Please below is the code and i need help to why the code was not working.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;

namespace TailspinSpyworks
{
    public partial class AddToCart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int productId;
            if (!String.IsNullOrEmpty(rawId) && Int32.TryParse(rawId, out productId))
            {
                MyShoppingCart usersShoppingCart = new MyShoppingCart();
                String cartId = usersShoppingCart.GetShoppingCartId();
                usersShoppingCart.AddItem(cartId, productId, 1);
            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx 
                                                   without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx 
                                                   without setting a ProductId.");
            }
            Response.Redirect("MyShoppingCart.aspx");
        }
    }
}


This is the error code generated by developerfusion.com
Quote:
An error occured converting your code, probably due to a syntax error:
-- line 25 col 28: No new line is allowed inside a string literal -- line 25 col 28: End of file reached inside string literal -- line 26 col 52: ")" expected -- line 26 col 72: No new line is allowed inside a string literal -- line 26 col 72: End of file reached inside string literal -- line 27 col 37: No new line is allowed inside a string literal -- line 27 col 37: End of file reached inside string literal -- line 28 col 80: No new line is allowed inside a string literal -- line 28 col 80: End of file reached inside string literal

Please any help is highly appreciated.Thanks
Posted
Comments
[no name] 2-May-13 10:04am    
you have errors in the existing code. fix the erros and then convert. The error tells you what you have to fix.

Remove these two lines:

Debug.Fail("ERROR : We should never get to AddToCart.aspx
                                                  without a ProductId.");
               throw new Exception("ERROR : It is illegal to load AddToCart.aspx
                                                  without setting a ProductId.");


Then try and convert it.
I suspect that is the issue.

If it converts, manually create those two lines yourself.
 
Share this answer
 
Comments
jamiebones 2-May-13 10:21am    
It worked as you suggested,thanks but how do i use the debug.fail statement
Pheonyx 2-May-13 10:23am    
Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.")
Throw New Exception ("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.")
jamiebones 2-May-13 10:43am    
Thanks God bless you
Please, avoid the questions on the translation from VB.NET to C# or back, because this all can be done automatically.

You can use Reflector or its open-source replacement ILSpy or one of similar tools:
http://en.wikipedia.org/wiki/.NET_Reflector[^],
http://ilspy.net/[^].

Additionally, this is one of effective tools to learn CIL. It can be very useful, and I don't know a good reference on the language. CIL knowledge is very important, in particular, for using System.Reflection.Emit, an extremely powerful library.

You can write code in one language, compile it, load the assembly with ILSpy, choose another language, and decompile the code part you need. The accuracy of the results is very good.

This is a stand-along open-source code convertor: http://codeconvert.codeplex.com/[^].

There is a number of on-line tools:
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^],
http://converter.telerik.com/[^].

You can find more: http://bit.ly/XFdX2G[^].

In some more complex cases, the accuracy can be questionable.

[EDIT]

I would strongly recommend that if you are develop in .NET, you should understand at least some C#, especially if you want to use solutions of other people. Best solutions will be found in C#, not VB.NET. The reasons are: VB.NET will hardly be ever standardized, while C# is standardized very thoroughly and comprehensively under ECMA and ISO/IEC; other reasons are cultural: most advanced developers don't take VB.NET seriously no matter how good it might be.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900