I know how to convert code in C# to VB.NET. But in this one small instance, i want to convert code from VB.NET into C#. :eek:
Does anyone know of a utility/webpage that does this? It's not a lot of code. Only maybe 10 lines or so.
Printable View
I know how to convert code in C# to VB.NET. But in this one small instance, i want to convert code from VB.NET into C#. :eek:
Does anyone know of a utility/webpage that does this? It's not a lot of code. Only maybe 10 lines or so.
Post the code here, we can all chip in :D
I can figure out the declaration of the string variables, the message box, the changes to the try-catch, and even the trailing semi colan.
But it's the XML objects and System variables i don't know how to change:That's why i was looking for a way to convert it; so i can see what the different syntax is.VB Code:
Dim sAppPath As String = System.Environment.CurrentDirectory Dim sFilename As String = sAppPath & "SampleFile.XML" Dim oXML As System.Xml.XmlDataDocument = New XmlDataDocument() oXML.Load(sFilename) Dim sTmp As String = "" Try sTmp = oXML.SelectSingleNode("//AppUpdateURL").InnerText Catch 'An error here might indicate that there is no node with that given name End Try MsgBox("the URL is: " & sTmp) oXML = Nothing
example
Dim oXML As System.Xml.XmlDataDocument = New XmlDataDocument()
=
System.Xml.XmlDataDocument oXML = new XmlDataDocument();
This is the converted version . It should works fine .;)
Code:public void C_Code(){
string sAppPath =System.Environment.CurrentDirectory;
string sFilename =sAppPath + "SampleFile.XML";
System.Xml.XmlDataDocument oXML = new System.Xml.XmlDataDocument();
oXML.Load(sFilename);
string sTmp =null;
try {
sTmp = oXML.SelectSingleNode("//AppUpdateURL").InnerText;
}
catch (System.Exception x) {
MessageBox.Show (x.Message);
}
MessageBox.Show ("the URL is: " + sTmp);
oXML = null;
}
I had to add a \\ before the name of the file because C# doesn't have the trailing backslash like VB.NET does. Other than that, all that code helps. It works. http://www.vbforums.com/
I have found a major flaw in my code. :mad: - The program crashes hard if the XML is NOT there. :eek:
In VB.NET i'd just use the Dir function to verify that the file/path was valid. I'll have to see if there is a translation for the Dir function in C#.
Actually,... if i just re-arrange the order of the items to have the .Load inside the TryCatch, i can avoid the error.
So that works fine then. :D Thanks.
Here is a trick you can use to eliminate the \\'s
You way now:
("\\AppUpdateURL")
Another way you can do it:
(@"\AppUpdateURL")
The @ sign in front of a string makes C# count it as a literal string, and tells it that there is no backslash constants in the string.
I was wondering what that was for. I'd seen it in a few examples, and i couldn't understand what it did.
Thanks! http://www.vbforums.com/