-
A syntax issue...
Hello. I am coding a simple project in VS 2010 (vb.net) that spits out formatted code strings for another program. In order for it to spit out the proper format it needs to be formatted properly in VS. I have one string formatted correctly in VS, and it looks like this:
TextBox2.Text = "run javascript(""document.getElementById(\""" & elid & "\"").selectedIndex =\""" & ddindex & "\"";"")"
where elid and ddindex are the variables. I have a second string that I just can't get formatted right in VS (elid, lowrange and highrange are the variables and everything in the following string needs to be written to the textbox including quotes, spaces, etc):
run javascript("document.getElementById(\"elid\").selectedIndex = {$rand("lowrange", "highrange")};//dropddown\")")
(that's the code I need spit out (of course replacing the variable names with the values)
I have been trying different variations for a week now and just can't come up with the correct string. Any help would be greatly appreciated! Thank you.
John
-
Re: A syntax issue...
Code:
"run javascript(""document.getElementById(\""" & elid.ToString() & "\"").selectedIndex = {$rand(""" & lowrange.ToString() & """, """ & highrange & """)};//dropddown\"")"")"
You can also look at String.Format(). Keep in mind that you'll need to do some additional escaping on certain characters (ie {, }, \, etc...).
-
Re: A syntax issue...
Wow Craig, thank you! That was fast and on the money, works beautifully. I tried string.format but had the same kind of issues with syntax errors, etc. If you don't mind, I am wondering why two of the three variables use ".ToString" and the other one does not. Thanks again!
John
-
Re: A syntax issue...
If I were to guess, it is because they contain numeric values ( Integers ), so they need to be cast to string to show the correct values as a String
-
Re: A syntax issue...
That's what I thought, except the wrong two would have been used (lowrange and highrange were integers and elid is already a string)...but it works nonetheless. For me that escaping process is really tricky. Do you guys know of any good resources I can review? I would love to read up on it. Thanks again.
John