VBScript Reference Manual for InduSoft Web Studio
VBScript Reference Manual for InduSoft Web Studio
VBScript Reference Manual for InduSoft Web Studio
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>InduSoft</strong> <strong>Web</strong> <strong>Studio</strong> <strong>VBScript</strong> <strong>Reference</strong> <strong>Manual</strong><br />
Byte, Integer & Long Variables<br />
These three data subtypes are whole numbers that vary by the range of values that they can hold. Note<br />
that the Byte data subtype has only a positive range (i.e. it is an unsigned value), while Integer and<br />
Long are signed values. Byte is an 8-bit number, Integer a 16-bit number and Long a 32-bit number.<br />
Subtype Range<br />
Byte 0 to 255<br />
Integer -32,768 to 32,767<br />
Long -2,147,483,648 to 2,147,483,647<br />
There are several types of operations that can be per<strong>for</strong>med on these data subtypes, such as<br />
arithmetic, comparison and logical operators. Also, many math functions can be used with these data<br />
subtypes. Some examples are:<br />
Dim MyByte, MyInt, MyHex<br />
MyByte = $input_val – 5 ‘ read integer IWS tag input_val and subtract 5<br />
If MyByte > 255 Then MyByte = 255 ‘ used in a condition statement. Make a byte value<br />
MyInt = 459<br />
MyHex = Hex(MyInt) ‘ returns 1CB<br />
In addition to these functions, there are Byte versions of string operations that can be used with Byte<br />
data contained in strings. For example, data from a serial port might be stored in a string. Remember<br />
that strings can be essentially any length. The Mid function could be used to return a specified number<br />
of characters from a string, but the MidB function will return a specified number of Bytes from the string.<br />
Currency Variables<br />
<strong>VBScript</strong> supports a currency data type. The valid range <strong>for</strong> currency is from -<br />
922,337,203,685,477.5808 to 922,337,203,685,477.5807. You can per<strong>for</strong>m most of the same<br />
operations on the currency data type as you can per<strong>for</strong>m on other numbers. The primary difference is<br />
that the currency data subtype will contain the currency symbol, and is <strong>for</strong>matted using the<br />
FormatCurrency function.<br />
Currency Format Function<br />
Function Description<br />
FormatCurrency Returns an expression <strong>for</strong>matted as a currency value<br />
Example1:<br />
Dim val, f_val ‘ This example limits the number of decimal places<br />
val = 123.456 ‘ assign a currency value to val<br />
f_val = FormatCurrency(val, 2) ‘ 2 digits after decimal, result is f_val = $123.45<br />
Example2:<br />
Dim price ‘ This example changes the currency symbol<br />
price = 123.456<br />
SetLocale(1033) ' Set locale to United States, use $ currency symbol<br />
curDollars = FormatCurrency(price, 2) ' curDollars set to $123.46<br />
myLocale = SetLocale(2057) ' Set locale to UK, use £ currency symbol<br />
curPounds = FormatCurrency(price, 2) ' curPounds set to £123.46<br />
Note: To use the Euro € symbol <strong>for</strong> a country that uses the Euro, make sure the system’s Region<br />
Settings is properly set, otherwise the pre-Euro symbol will be used.<br />
<strong>InduSoft</strong>, Ltd. 69