How to translate this C# into VB (generally)

D

Dean Slindee

This chunk of code does not translate accurately using the available C# to
VB translator tools.
I am wondering what the "sub within a sub" structure should look like in VB:
starting with the
"public void Fill(DataSet ds)" and "tds = this;" statements. (Sorry, the
indentation did not come across).
Thanks for looking,
Dean Slindee


using System;

using System.Data;

using System.Xml;

namespace Rosters

{

public class TypedDataSet: roster

{

private TypedDataSet tds;


public void Fill(XmlDocument doc)

{

// First populate an untyped DataSet with the xml document

DataSet ds = new DataSet();

byte [] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(doc.OuterXml);

System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);

ds.ReadXml(ms);

ms.Close();

// Then fill the typed DataSet from the untyped DataSet

Fill(ds);

}


public new void ReadXml(string xmlFile)

{

XmlDocument xmlDoc = new XmlDocument();

try

{

xmlDoc.Load(xmlFile);

this.Fill(xmlDoc);

}

catch (XmlException)

{

// ignore or handle exception here

}


public void Fill(DataSet ds)

{

tds = this;

// Map each row of each table in the untyped DataSet to a

// corresponding item in the strongly typed DataSet

for ( int i = 0; i < ds.Tables.Count; i++ )

{

foreach (DataRow iDr in ds.Tables.Rows)

{

DataRow oDr = tds.Tables.NewRow();

for ( int j = 0; j < ds.Tables.Columns.Count; j++ )

try

{

oDr[j] = iDr[j].ToString();

}

catch (NoNullAllowedException)

{

// ignore for now - just in

// case no such column in DataSet

}

tds.Tables.Rows.Add(oDr);

}

}

tds.AcceptChanges();

}

}

}
 
O

One Handed Man [ OHM# ]

Slindee,

One problem is that you have a missing right brace in the C# code. Try
putting this code back into C#. You will notice the error, then try and
import it again to VB

Regards - OHM#


Dean said:
This chunk of code does not translate accurately using the available
C# to VB translator tools.
I am wondering what the "sub within a sub" structure should look like
in VB: starting with the
"public void Fill(DataSet ds)" and "tds = this;" statements.
(Sorry, the indentation did not come across).
Thanks for looking,
Dean Slindee


using System;

using System.Data;

using System.Xml;

namespace Rosters

{

public class TypedDataSet: roster

{

private TypedDataSet tds;


public void Fill(XmlDocument doc)

{

// First populate an untyped DataSet with the xml document

DataSet ds = new DataSet();

byte [] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(doc.OuterXml);

System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);

ds.ReadXml(ms);

ms.Close();

// Then fill the typed DataSet from the untyped DataSet

Fill(ds);

}


public new void ReadXml(string xmlFile)

{

XmlDocument xmlDoc = new XmlDocument();

try

{

xmlDoc.Load(xmlFile);

this.Fill(xmlDoc);

}

catch (XmlException)

{

// ignore or handle exception here

}


public void Fill(DataSet ds)

{

tds = this;

// Map each row of each table in the untyped DataSet to a

// corresponding item in the strongly typed DataSet

for ( int i = 0; i < ds.Tables.Count; i++ )

{

foreach (DataRow iDr in ds.Tables.Rows)

{

DataRow oDr = tds.Tables.NewRow();

for ( int j = 0; j < ds.Tables.Columns.Count; j++ )

try

{

oDr[j] = iDr[j].ToString();

}

catch (NoNullAllowedException)

{

// ignore for now - just in

// case no such column in DataSet

}

tds.Tables.Rows.Add(oDr);

}

}

tds.AcceptChanges();

}

}

}


Regards - OHM# (e-mail address removed)
 
D

Dean Slindee

You are correct about the missing squirrelly bracket (as posted on Code
Project). However, the translation result was the same. The translator (am
I) are thoroughly confused as to how to write a sub inside a sub!

Any ideas?

Thanks,
Dean Slindee
One Handed Man said:
Slindee,

One problem is that you have a missing right brace in the C# code. Try
putting this code back into C#. You will notice the error, then try and
import it again to VB

Regards - OHM#


Dean said:
This chunk of code does not translate accurately using the available
C# to VB translator tools.
I am wondering what the "sub within a sub" structure should look like
in VB: starting with the
"public void Fill(DataSet ds)" and "tds = this;" statements.
(Sorry, the indentation did not come across).
Thanks for looking,
Dean Slindee


using System;

using System.Data;

using System.Xml;

namespace Rosters

{

public class TypedDataSet: roster

{

private TypedDataSet tds;


public void Fill(XmlDocument doc)

{

// First populate an untyped DataSet with the xml document

DataSet ds = new DataSet();

byte [] buf = System.Text.ASCIIEncoding.ASCII.GetBytes(doc.OuterXml);

System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);

ds.ReadXml(ms);

ms.Close();

// Then fill the typed DataSet from the untyped DataSet

Fill(ds);

}


public new void ReadXml(string xmlFile)

{

XmlDocument xmlDoc = new XmlDocument();

try

{

xmlDoc.Load(xmlFile);

this.Fill(xmlDoc);

}

catch (XmlException)

{

// ignore or handle exception here

}


public void Fill(DataSet ds)

{

tds = this;

// Map each row of each table in the untyped DataSet to a

// corresponding item in the strongly typed DataSet

for ( int i = 0; i < ds.Tables.Count; i++ )

{

foreach (DataRow iDr in ds.Tables.Rows)

{

DataRow oDr = tds.Tables.NewRow();

for ( int j = 0; j < ds.Tables.Columns.Count; j++ )

try

{

oDr[j] = iDr[j].ToString();

}

catch (NoNullAllowedException)

{

// ignore for now - just in

// case no such column in DataSet

}

tds.Tables.Rows.Add(oDr);

}

}

tds.AcceptChanges();

}

}

}


Regards - OHM# (e-mail address removed)
 
P

Peter Huang

Hi Dean,

What do you mean "Sub inside a sub"?
Do you mean the For statement nested with another for statement?

I think this may be caused by your tool's limitation.
You may take a look at the tool below.
http://authors.aspalliance.com/aldotnet/examples/translate.aspx
http://csharpconverter.claritycon.com/Default.aspx

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
E

emailallrise

check out msdn site for vb.net, they r distributing vb.net resource kit
which comes with a fine C# to vb converter.
 
A

Armin Zingler

emailallrise said:
check out msdn site for vb.net, they r distributing vb.net resource kit
which comes with a fine C# to vb converter.

I think Peter knows this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top