Promotic
WikipediaLinkedInYoutubeTwitterFacebook

TransformValue - method of object Pm

Description:
Transformation of the value.
Syntax:
TransformValue(vValue As Variant, nType As Integer) As Variant
Calling:
x = Pm.TransformValue(vValue, nType)
Parameters:
vValue(Variant) Value that is transformed
nType(Integer) Type of transformation
1 - 12 -> 21 - Swaps 1st and 2nd byte in the Integer type value (see Example1). It is so called 2-Byte value transfomation from LittleEndian to BigEndian (or backwards).
2 - 1234 -> 4321 - Swaps 1st and 4th byte and 2nd and 3rd byte in the Long type value. It is so called 4-Byte value transfomation from LittleEndian to BigEndian (or backwards).
20 - Long -> BCD - Transforms a value of Long type (from the range 0-99999999) to BCD format in Long type (see Example2).
21 - BCD -> Long - Transforms a value of Long type in BCD format to Long type.
40 - ElementArray -> Array - Transforming an array where the array items are of a real elementary data type (i.e. instead of being Variant type) into the standard (VBScript) form, where each array item is represented by a Variant type value of specified subtype. This kind of transformation may be handy, for example, if the array is gained from a communication or from a DLL library function.
41 - Array -> ElementArray - Transforming the standard VBScript array, where the array items are of the Variant data type, into the array where each array item is represented by the same elementary data type (i.e. instead of being Variant type). This kind of transformation may be handy, for example, if the array is being sent into a communication (for OPC see Data vector transfer) or into a DLL library function.
50 - Matrix -> TranspMatrix - In a value of the array type (two-dimensional Array), the mutual counterchange of columns and rows is performed (transposed array).
100 - Simatic -> Single - Transforms a value of Single type from the real number format PLC SIMATIC S5.
101 - Single -> Simatic - Transforms a value of Single type into the real number format PLC SIMATIC S5.
120 - Real -> "99x9" - The value will be converted to string, where for real numbers (Single, Double or Date) the decimal separator will be used according to the OS Windows settings.

This and the following two transformations are suitable, for example, for saving the values into text files, see Data sharing by files. See also Pm.CDbl, CStr.

121 - Real -> "99.9" - The value will be converted to string, where for real numbers (Single, Double or Date) the period (".") will be used as decimal separator regardles to OS Windows settings.
122 - Real -> "99,9" - The value will be converted to string, where for real numbers (Single, Double or Date) the comma (",") will be used as decimal separator regardles to OS Windows settings.
200 - Value -> Array of Boolean - Creates the binary array (Array) with values of the Boolean type (see Example3). Each value of the array has one bit value of the vValue parameter. The vValue parameter can be of:
- Byte type: there are 8 values in the array (opposite to the transformation type 221)
- Integer type: there are 16 values in the array (opposite to the transformation type 222)
- Long type: there are 32 values in the array (opposite to the transformation type 223)
- Single type: there are 32 values in the array (opposite to the transformation type 224)
- Double type: there are 64 values in the array (opposite to the transformation type 225)
201 - Value -> Array of Byte - Creates the binary array (Array) with values of the Byte type. Each value of the array has one byte value of the vValue parameter. The vValue parameter can be of:
- Byte type: there is 1 value in the array (opposite to the transformation type 221)
- Integer type: there are 2 values in the array (opposite to the transformation type 222)
- Long type: there are 4 values in the array (opposite to the transformation type 223)
- Single type: there are 4 values in the array (opposite to the transformation type 224)
- Double type: there are 8 values in the array (opposite to the transformation type 225)
202 - Value -> Array of Integer - Creates the binary array (Array) with values of the Integer type. Each value of the array has two bytes value of the vValue parameter. The vValue parameter can be of:
- Integer type: there is 1 value in the array (opposite to the transformation type 222)
- Long type: there are 2 values in the array (opposite to the transformation type 223)
- Single type: there are 2 values in the array (opposite to the transformation type 224)
- Double type: there are 4 values in the array (opposite to the transformation type 225)
203 - Value -> Array of Long - Creates the binary array (Array) with values of the Long type. Each value of the array has four bytes value of the vValue parameter. The vValue parameter can be of:
- Long type: there is 1 value in the array (opposite to the transformation type 223)
- Single type: there is 1 value in the array (opposite to the transformation type 224)
- Double type: there are 2 values in the array (opposite to the transformation type 225)
221 - Array -> Byte - Creates the binary value of the Byte type. The vValue parameter can be:
- array (Array) with 8 values of the Boolean type (opposite to the transformation type 200)
- array (Array) with 1 value of the Byte type (opposite to the transformation type 201)
222 - Array -> Integer - Creates the binary value of the Integer type. (see Example3). The vValue parameter can be:
- array (Array) with 16 values of the Boolean type (opposite to the transformation type 200)
- array (Array) with 2 values of the Byte type (opposite to the transformation type 201)
- array (Array) with 1 value of the Integer type (opposite to the transformation type 202)
223 - Array -> Long - Creates the binary value of the Long type. The vValue parameter can be:
- array (Array) with 32 values of the Boolean type (opposite to the transformation type 200)
- array (Array) with 4 values of the Byte type (opposite to the transformation type 201)
- array (Array) with 2 values of the Integer type (opposite to the transformation type 202)
- array (Array) with 1 value of the Long type (opposite to the transformation type 203)
- value of the Single type (opposite to the transformation type 224)
224 - Array -> Single - Creates the binary value of the Single type. The vValue parameter can be:
- array (Array) with 32 values of the Boolean type (opposite to the transformation type 200)
- array (Array) with 4 values of the Byte type (opposite to the transformation type 201)
- array (Array) with 2 values of the Integer type (opposite to the transformation type 202)
- array (Array) with 1 value of the Long type (opposite to the transformation type 203)
- value of the Long type (opposite to the transformation type 223)
225 - Array -> Double - Creates the binary value of the Double type. The vValue parameter can be:
- array (Array) with 64 values of the Boolean type (opposite to the transformation type 200)
- array (Array) with 8 values of the Byte type (opposite to the transformation type 201)
- array (Array) with 4 values of the Integer type (opposite to the transformation type 202)
- array (Array) with 2 values of the Long type (opposite to the transformation type 203)
240 - Array -> HexaString - The input is represented by Array type value with all items of the Byte type. The output is represented by the String type value with so called HexaString content.

Example: If the Array input value contains three values of the Byte type, for example 1A 00 B8 (hexadecimaly), then the output would be a String containing six "1A00B8" characters.

This is handy if you need to save binary data into the text.

241 - HexaString -> Array - The opposite of previous transformation, i.e. from HexaString it creates Array with all items of the Byte type
Return Values:
Returns the transformed value of the respective type. The error is indicated by returning the value of the Empty type (it can be tested by the Pm.IsValid method).
Note:

The method performs various types of value transformations that cannot be done simply by the script functions.

Note for values in PLC SIMATIC S5: Values on this PLC have different internal format compared to PC format. Real values are converted by the transformation type 100 (101), Integer values are converted by the transformation type 1 (2).

Note for the BCD (Binary Coded Decimal) format: each digit of the number in the decimal notation is stored to 4 bits. This means that in the Long type there are 8 digits (range 0-99999999). This format is used often in various HW devices. The constant in the BCD format can be easily written in the way that the decimal number is introduced by the prefix for the hexadecimal notation, so that the constant 999 transformed to BCD value is &h999.

 
This method is not so far functional for Web Panels.
Example1:
Exchange of bytes in a value of the Integer type (in 2-bytes value)
Dim Val, ValNew
Val = 3
ValNew = Pm.TransformValue(Val, 1)
In the ValNew variable is now the value, which is 300 hexadecimal. It means that the &h0003 value has been transformed to the &h0300 value.
Example2:
Transformation of the value 999 to BCD format and the check if an error doesn't occur. Writing the same value in the form of a constant with using the hexadecimal notation.
Dim Val, ValNew
Val = 999
ValNew = Pm.TransformValue(Val, 20)
If Pm.IsValid(ValNew) Then
  Pm.Debug ValNew
  Pm.Debug &h999
End If
Example3:
Converts the value -2 of the Integer type in the Val1 variable to the bit array (to the array of values of the Boolean type) to the Arr variable (the value -2 is 1111111111111110 in binary format). Then the value of the Long type is created back from this array to the Val2 variable. For control purposes the detailed information about the variables Arr and Val2 is written into the INFO system by the Pm.Debug method.
Dim Val1, Arr, Val2
Val1 = CInt(-2)
Arr = Pm.TransformValue(Val1, 200)
Val2 = Pm.TransformValue(Arr, 222)
Pm.Debug Arr,1
Pm.Debug Val2,1
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- LN2
- PI
- Pow
- Sin
- Tan
- TransformValue
 
 
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice