18.01.2013 Views

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

VBScript Reference Manual for InduSoft Web Studio

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong> <strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong><br />

While <strong>VBScript</strong> string handling capability can be very useful, programmers should be aware of<br />

in<strong>for</strong>mation given in Microsoft Knowledge Base Article 170964 1 . This article states that when strings get<br />

very large (e.g. 50kB or larger), the time to concatenate these strings can be very long. For example, a<br />

typical string concatenation where:<br />

Dim dest, source ‘ String variables<br />

Dim i, N<br />

For i = 1 to N<br />

dest = dest & source<br />

Next N<br />

Using the programming method above, the Article notes that the length of time to per<strong>for</strong>m the<br />

concatenation increase proportionately to N-squared. This increase in time is due to the method<br />

<strong>VBScript</strong> uses to concatenate strings, which is:<br />

• allocate temporary memory large enough to hold the result.<br />

• copy the dest string to the start of the temporary area.<br />

• copy the source string to the end of the temporary area.<br />

• de-allocate the old copy of dest.<br />

• allocate memory <strong>for</strong> dest large enough to hold the result.<br />

• copy the temporary data to dest.<br />

The Article details a method using the Mid$ statement and pre-allocation of memory to significantly<br />

reduce the time to concatenate large strings. Also, you can reference the section on Classes <strong>for</strong><br />

another method to speed string concatenation.<br />

There are several functions available to manipulate strings. Refer to the reference material in the<br />

Appendix <strong>for</strong> a detail description of these functions.<br />

String Functions<br />

Function Description<br />

InStr Returns the position of the first occurrence of one string within another. The search begins at the<br />

first character of the string<br />

InStrRev Returns the position of the first occurrence of one string within another. The search begins at the<br />

last character of the string<br />

LCase Converts a specified string to lowercase<br />

Left Returns a specified number of characters from the left side of a string<br />

Len Returns the number of characters in a string<br />

LTrim Removes spaces on the left side of a string<br />

Mid Returns a specified number of characters from a string<br />

Replace Replaces a specified part of a string with another string a specified number of times<br />

Right Returns a specified number of characters from the right side of a string<br />

RTrim Removes spaces on the right side of a string<br />

Space Returns a string that consists of a specified number of spaces<br />

StrComp Compares two strings and returns a value that represents the result of the comparison<br />

String Returns a string that contains a repeating character of a specified length<br />

StrReverse Reverses a string<br />

Trim Removes spaces on both the left and the right side of a string<br />

UCase Converts a specified string to uppercase<br />

1 See http://support.microsoft.com/kb/q170964/<br />

<strong>InduSoft</strong>, Ltd. 75

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!