Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# LINQ VB.NET convert
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 2-May-13 5:01am
Comments
FRCTeam2168 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
jamiebones at 2-May-13 10:21am
   
It worked as you suggested,thanks but how do i use the debug.fail statement
Pheonyx at 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 at 2-May-13 10:43am
   
Thanks God bless you
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 250
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 DamithSL 125
4 Afzaal Ahmad Zeeshan 120
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100