C# to VB batch conversion (minor issues)

1 posts, 0 answers
  1. Mych
    Mych avatar
    18 posts
    Member since:
    Sep 2012

    Posted 13 Sep 2012 Link to this post

    This is the first time I have used the converter and have found it to be great although I did still have to do some minor changes in order for the converted code to work. Listing here to help others...

    1. HANDLES not added:
    e.g. protected void Page_Load(object sender, EventArgs e) converted to
           Protected Sub Page_Load(ByVal sender as Object, ByVal e as System.EventArgs)
    in order to work I had to add Handles to the end of each event sub line. In the case above I added Handles Me.Load 

    2. Concatenation of strings:
    e.g.  string today = "";
    today = yy + mm + dd + "_Returns_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + Session["User"].ToString();
    converted to:
    Dim today As String = ""
    today = yy + mm + dd + "_Returns_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + Session["User"].ToString()
           In some cases using + to join two strings in VB will work but if this case the first three element are integers and you get a CAST error. I ended up going through the code and replacing + with & (Don't do this globaly though as it will replace the + in mathematical calculations).
    The line above became
    today = yy & mm & dd & "_Returns_" & DateTime.Now.ToLongTimeString().Replace(":", "_") & Session["User"].ToString() It could also be written as:
    today = yy.ToString() + mm.ToString() + dd.ToString() + "_Returns_" + DateTime.Now.ToLongTimeString().Replace(":", "_") + Session["User"].ToString()

    Otherwise a very good conversion. Converted 32 C# files and made the above alterations and was done within an hour.
Back to Top