CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2011
    Posts
    3

    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

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Arrow 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...).
    Last edited by Craig Gemmill; November 19th, 2011 at 06:55 PM.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Nov 2011
    Posts
    3

    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

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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

  5. #5
    Join Date
    Nov 2011
    Posts
    3

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured