|
-
Apr 3rd, 2003, 11:44 AM
#1
Thread Starter
Frenzied Member
Convert Code to C# ?
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#.
Does anyone know of a utility/webpage that does this? It's not a lot of code. Only maybe 10 lines or so.
~Peter

-
Apr 3rd, 2003, 11:46 AM
#2
Frenzied Member
Post the code here, we can all chip in
Dont gain the world and lose your soul
-
Apr 3rd, 2003, 12:12 PM
#3
Thread Starter
Frenzied Member
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:
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
That's why i was looking for a way to convert it; so i can see what the different syntax is.
~Peter

-
Apr 3rd, 2003, 12:23 PM
#4
example
Dim oXML As System.Xml.XmlDataDocument = New XmlDataDocument()
=
System.Xml.XmlDataDocument oXML = new XmlDataDocument();
-
Apr 3rd, 2003, 12:40 PM
#5
Sleep mode
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;
}
-
Apr 3rd, 2003, 12:57 PM
#6
Thread Starter
Frenzied Member
-
Apr 3rd, 2003, 01:08 PM
#7
Thread Starter
Frenzied Member
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. Thanks.
~Peter

-
Apr 3rd, 2003, 01:09 PM
#8
PowerPoster
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.
-
Apr 4th, 2003, 02:42 PM
#9
Thread Starter
Frenzied Member
I was wondering what that was for. I'd seen it in a few examples, and i couldn't understand what it did.
Thanks!
~Peter

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|