SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Free VB.NET to C# translator...

Latest post 11-17-2005 10:05 AM by microlau. 2 replies.
  • 11-14-2005 9:18 AM

    Free VB.NET to C# translator...

    Works for C# to VB.NET as well.

    microlau Blog: http://community.sgdotnet.org/blogs/microlau

  • 11-16-2005 2:42 PM In reply to

    Re: Free VB.NET to C# translator...

    Doesn't convert "perfectly". Try this code snippet, it will continue to use ( ) parenthesis instead of [ ] square brackets for array and DataRow indexes.

    Dim Keys(1) As DataColumn

    ' create a data table
    Dim dt As New DataTable("TableTest")

    ' create a number column
    Dim dcNumber As New DataColumn("NumberColumn", GetType(Int32))
    dt.Columns.Add(dcNumber)

    ' add this column to the keys array, apply as primary key
    Keys(0) = dcNumber
    dt.PrimaryKey = Keys

    ' create a string column
    Dim dcString As New DataColumn("StringColumn", GetType(String))
    dcString.MaxLength = 50
    dt.Columns.Add(dcString)

    ' create a date column
    Dim dcDate As New DataColumn("DateColumn", GetType(Date))
    dt.Columns.Add(dcDate)

    ' add a row
    Dim row As DataRow = dt.NewRow()
    row("NumberColumn") = 1
    row("StringColumn") = "Test on row 1"
    row("DateColumn") = Now
    dt.Rows.Add(row)

    ' add a second row
    row = dt.NewRow()
    row("NumberColumn") = 2
    row("StringColumn") = "Test on row 2"
    row("DateColumn") = Now.AddDays(1)
    dt.Rows.Add(row)

    ' bind the table to the grid
    UltraGrid1.DataSource = dt

    The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

  • 11-17-2005 10:05 AM In reply to

    Re: Free VB.NET to C# translator...

    Hmm.. Interesting. Here's the C# codes after conversion:

    DataColumn[,] Keys;
    DataTable dt = new DataTable("TableTest");
    DataColumn dcNumber = new DataColumn("NumberColumn", typeof(Int32));
    dt.Columns.Add(dcNumber);


    //  add this column to the keys array, apply as primary key
    Keys(0) = dcNumber;
    dt.PrimaryKey = Keys;
    DataColumn dcString = new DataColumn("StringColumn", typeof(string));
    dcString.MaxLength = 50;
    dt.Columns.Add(dcString);
    DataColumn dcDate = new DataColumn("DateColumn", typeof(DateTime));
    dt.Columns.Add(dcDate);
    DataRow row = dt.NewRow();
    row("NumberColumn") = 1;
    row("StringColumn") = "Test on row 1";
    row("DateColumn") = Now;
    dt.Rows.Add(row);

    //  add a second row
    row = dt.NewRow();
    row("NumberColumn") = 2;
    row("StringColumn") = "Test on row 2";
    row("DateColumn") = Now.AddDays(1);
    dt.Rows.Add(row);

    //  bind the table to the grid
    UltraGrid1.DataSource = dt;

    microlau Blog: http://community.sgdotnet.org/blogs/microlau

Page 1 of 1 (3 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems