Help converting to VB.NET

samsmithnz

Well-known member
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
Hi, Ive been converting a conversion function from the internet today from C# to VB.NET. Im pretty close, but I have two lines Im not sure about, and I was wondering if anyone could help. The lines in question are:

The C# code line 1:
Code:
selectHtml = selectHtml +  "; parent.ShowLookupAdditionalInfo(\""+ HttpUtility.HtmlAttributeEncode(TextFieldId) + "\",\""+ "$$ADDITIONALINFO$$" +"\")";
This is what I have... what are the $$ supposed to be, its coming up as a syntax error
Code:
selectHtml = selectHtml +  "; parent.ShowLookupAdditionalInfo(\""+ HttpUtility.HtmlAttributeEncode(TextFieldId) + "\",\""+ "$$ADDITIONALINFO$$" +"\")"

The C# code line 2:
Code:
selectHtml = selectHtml +  "; parent.document.all(\""+ HttpUtility.HtmlAttributeEncode(TextFieldId) + "\").fireEvent(\"onChange\");";
This is what I have... the \ in the last part (\"onChange\") is throwing an error, whats wrong here then?
Code:
selectHtml = selectHtml +  "; parent.document.all(\""+ HttpUtility.HtmlAttributeEncode(TextFieldId) + "\").fireEvent(\"onChange\");"

Sorry this post is so wide...
 
Last edited by a moderator:
I think you are having formatting issues, I dont think the $$ is your problem.

For one thing, in C#.net, you cant have just one \\ in a string, its an invalid escape character, so C# coders produce the string:
C:\Windows

by doing this:

[CS]
string mystring = "C:\\Windows";
[/CS]

So to translate that back to VB.net you need to do:

[VB]
dim mystring as string = "C:\Windows"
[/VB]

Another issue is that you cant have quotes within a quote.

if you need to have a quote in the string you need to replace it with something like
Code:
 & Convert.ToChar(34) &

So, go through your strings, and make those changes. You have a couple of invalid strings that you will need to figure out. For instance this:

"\","\"

will not work. I am not sure what you were doing there.
Anyway, make the changes and see what happens. I imagine the $$ will not be an issue any longer. Also, I am unsure, but if the $ is an invalid char by itself in C# then you will only need one in VB.net as well. You may need to look into that.

Good luck,
Brian
 
ahhh that makes sense. I forgot the \ was an escape character.

incidently to escape a " in VB, you only need to add another one, so "". It sure starts to look confusing when you have stuff like this though:

Code:
String = """Hello"""

which returns:

"Hello"

one other quick question. Is the \ an escape chacter in Javascript too?
 
as well as using 2 \\ you can also do the @ thing as with C++ when using C# , eg:
C#:
string mystring = "C:\\Windows";

// same is achieved with this ...

string mystring = @"C:\Windows";
 
ahhh, I always wondered what that random @ was in some c# code samples Ive converted.

Luckily the code I converted was never that cricital...
 
Back
Top