• String(n,c): does it work in VBS?

    Home » Forums » Developers, developers, developers » Web design and development » String(n,c): does it work in VBS?

    Author
    Topic
    #380855

    I’ve been abused by the String() function in VBS.

    In a class, with a class variable int, calling

    result = String(int,".")

    just does not work! Changing the code to

    result = String(CInt(int),".")

    doesnt work. Setting another variable like this

    dim L
    L = CInt(int)
    result = String(L,".")

    doesnt work either.

    What am I overlooking?

    Viewing 0 reply threads
    Author
    Replies
    • #639443

      According to my book, the number is supposed to be a Long, but since VBS is not strongly typed, I find that hard to believe. This code, when run from a .vbs file on the desktop, works for both:

      Dim int, lng
      int = 5
      int = CInt(int)
      msgbox String(int,”X”)
      lng = 10
      lng = CLng(lng)
      msgbox String(lng,”X”)

      Is it possible that int has somehow become null when you get to the String function?

      • #639518

        I just tired a small class and it’s working ~ there must be something else in the slightly larger class that i am not seeing.

      • #639608

        MISSPELLED VARIABLE!!! barf

        • #639620

          My sympathy. We’ve all been there and done that. Glad you found it!

          StuartR

          • #639625

            What irks me is that doesnt work as protection, but does.

            The school of experience definitely has the highest tuition. smile

            • #639652

              Hi Peter,

              I assume that the project you’re currently working on will be presented in the ASP environment?

              I’ve learned a few tricks about optimizing Classic ASP code that I’ll pass on, just in case you (or someone else) may find them helpful:

              (This may explain why the Option Explicit isn’t working properly if it follows the tag)
              As an ASP page is processed, the code inside the script blocks () is handled by a separate process from the standard HTML code. As it turns out, the page will process much faster with fewer script blocks – because the Script engine will have much less back-and-forth to do with IIS.

              One way you can help your code is by using the Response.Write() command for small blocks of HTML rather than closing and reopening the Script block just for a couple of markup tags. Of course, the extreme would be to build the whole page in Script syntax. I don’t think it makes enough difference to make that worthwhile, but I was surprised how much faster things seemed to run by eliminating some of the script starts and stops… (I’d be curious to hear the actual time results if anyone knows of testing that’s been done on this.)

              Which brings me to your Option Explicit issue. I wonder if the problem results from placing that declaration anywhere AFTER the page is passed to IIS (and then back to the Script engine). That might explain why it works properly when it comes before any markup. Just a thought…

              Also, I usually try to write as much Script before writing ANY markup. As mentioned above, there will usually be at least some script mixed in with HTML, but I try to keep it to a minimum…

              Hope this helps!

            • #639713

              Mark ~ Your points are well taken, as usual!

              In order to stay sane, I’ve tried to develop some rules for developing with VBS. So far, that means that my VBS script pages have this format:

              #include virtual="filename", repeat as necessary
              
               and the rest of the markup
              ... etc.
              
              
              
              

              For pure classes, the files are simpler:

              
              

              I strive to have 0 “script variables” and keep everything inside classes. Also note that altho VBS calls them classes, they’re really just capsules.

    Viewing 0 reply threads
    Reply To: String(n,c): does it work in VBS?

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: