Update cookies preferences
Promotic

Data types VBScript

VBScript has only one data type called a Variant. It is a special kind of the data type that can contain different kinds of information, depending on how it's used. Because Variant is the only data type in VBScript, it's also the data type returned by all functions in VBScript.
At its simplest, a Variant can contain numeric or string information. A Variant behaves as a number when you use it in a numeric context and as a string when you use it in a string context. That is, if you're working with data that looks like numbers, VBScript assumes that it is numbers and does the thing that is most appropriate for numbers. Similarly, if you're working with data that can only be string data, VBScript treats it as string data. Of course, you can always make numbers behave as strings by enclosing them in quotation marks ("").

Variant Subtypes:
Beyond the simple numeric or string classifications, a Variant can make further distinctions about the specific nature of numeric information. For example, you can have numeric information that represents a date or a time. When used with other date or time data, the result is always expressed as a date or a time. Of course, you can also have a rich variety of numeric information ranging in size from Boolean values to huge floating-point numbers. These different categories that can be contained in a Variant are called subtypes.

The following table shows the subtypes of data that a Variant can contain:

subtype Description
Boolean Logical value:
true (numeric value is "nonzero", usually -1) or
false (numeric value is 0)

See the notes below.
Byte Integer (1 byte) in the range: 0 to 255.
Integer Integer (2 bytes) in the range: -32768 to 32767.
Long Integer (4 bytes) in the range: -2,147,483,648 to 2,147,483,647.
Hexadecimal value of number can be entered directly by preceding numbers in the proper range with &H. For example, &H10 in hexadecimal represents decimal 16.
Single Real number (4 bytes) with the precision 7 digits in the range:
-3.402823E38 to -1.401298E-45 (negative number).
1.401298E-45 to 3.402823E38 (positive number).
Binary implementation format is according to standard IEEE-754 (32-bit)
Double Real number (8 bytes) with the precision 15 digits in the range:
-1.79769313486231E308 to -4.94065645841247E-324 (negative number).
4.94065645841247E-324 to 1.79769313486231E308 (positive number).
Binary implementation format is according to standard IEEE-754 (64-bit)
Date Value containing Date and time. See the notes below.
String Text string that can be up to approximately 2 billion characters in length in the Unicode character set.
Object "pointer" (reference) to object.
Array Array of values. See How to use array of values in the PROMOTIC system.
Empty Flag that value is uninitialized.
Null Flag that value contains no valid data.
Nothing Flag that value contains no valid object.


For conversion of the data into another data subtype, the conversion VBScript functions can be used: CBool, CByte, CInt, CLng, CSng, CDbl, CDate, CStr.
For testing if the variable can be evaluated in the subtype, the following VBScript functions can be used: IsNumeric, IsDate, IsObject, IsEmpty, IsNull, IsArray. By the functions VarType and TypeName it is possible to find out the subtype of the variable. Although it is better to use the Pm.GetVarType and Pm.IsValid methods.

Notes for numeric data types Byte, Integer and Long:

Setting the values with constant in hexadecimal:
It is possible to enter a number as constant in decimal, for example:
nVal = 36524
or in hexadecimal, where the &h prefix is used, for example:
nVal = &h8EAC
(8EAC in hexadecimal is 36524 in decimal).
But the VBScript evaluates the hexadecimal constants the following way: if the constant is 2-byte (like we have here), then it creates Integer data type. Because the 8EAC value has the highest bit set, then the constant will be considered as negative number equal to -29012!

Notes for Boolean data type:

Value of the Boolean type can logicaly have just two states (true / false), but it is actually stored as Integer data type and it is supposed that false is zero and true is non-zero.
And this way of understanding the true value can cause trouble, because by default the value is -1, but also any other non-zero value is also true !! That is why we do not recommend comparing the true values.
Example:
If value = true Then ...

This kind of condition is not advisable, because if the value of the value variable is for example 2, then the condition is evaluated as false, even if from the logical point of view it should be true (the value is non-zero and therefore true). It is recommended not to compare with true (because true can be represented by multiple values), but to compare only with false (false is always zero).
For our case it is better to make the condition as follows:
If Not value = false Then ...

Notes for Date data type:

If the value of date and time is of the Date type, then the values of year/month/day/hour/minute/second can be obtained, for example:
- by means of the PmDateObject object and its methods GetYear/GetMonth/GetDay/GetHour/GetMinute/GetSecond etc.
- by the VBScript methods Year/Month/Day/Hour/Minute/Second.
See also Pm date and time methods and VBScript date and time functions.

Date creating from value of the String type:
The required date (time, date and time) must be written into quotation marks in the format specified in Windows OS settings "Control Panel / Date/Time / Date and time tab". For example, if the date is set to the format d.M.yyyy in the local setting, then the time can be entered as String as follows:
Dim MyTime, MyDate, MyDateTime
MyTime = CDate("18:59:33")
MyDate = CDate("31.12.2024")
MyDateTime = CDate("31.12.2024 18:59:33")


Date creating by the VBScript constant:
If the date (time, date and time) is entered by this way, then it doesn't depend on setting the computer and the date (time, date and time) will always be in the correct format. The date (time, date and time) is entered by the # char in the format #dd/mm/yy# (or #hh:mm:ss# or #dd/mm/yy hh:mm:ss#):
Dim MyTime, MyDate, MyDateTime
MyTime = #18:59:33#
MyDate = #23/10/05#
MyDateTime = #23/10/13 18:59:33#


Date creating from real number:
The date (year, month, day) is represented by the whole part of the real number - it is a number of days since 30.12.1899. Value 1.0 refers to the date 31.12.1899, value –1.0 refers to the date 29.12.1899.
The time (hour, minute, second) is represented by the decimal part of the real number. The value x.5 means the exact midday (12:00:00) in the day x.
The value from 0.0 to 1.0 is a special case. The value is not considered to be a date but only as time or time span. The 0.5 value means 12 hours, the 1/24/60 value means 1 minute.
 
The following script assigns the value of date and time greater by one day and by one minute into the MyDateTime variable on each execution of the script.
MyDateTime = CDate(MyDateTime + 1 + 1/24/60)
If the MyDateTime variable is initialized by value 1, then after the first execution of the script, the value of the variable equals to "1.1.1900 0:01:00", after the second execution, the value equals to "2.1.1900 0:02:00".
PROMOTIC 9.0.29 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.