FileBinaryRead - method of the Pm object

Reading the content of the binary file into the variable of the Array type (into the array of values).
This method is obsolete (but functional) and it is better to use the PmBuffer.LoadFromFile method.
Long FileBinaryRead(String sFile, Long nOffset, Long nAttr, Variant Values)
sFile(String) The file name with the path.
If a full path is not entered, then it is completed relative to the application folder.
It is recommended to use the PROMOTIC path syntax - see PROMOTIC path to files and folders.
nOffset(Long) Byte offset that sets the beginning of reading from the binary file (e.g. 10 means reading from 10th byte of the file).
nAttr(Long) Bit attribute. It can be 0 or a sum of the following applicable values:
1 - Flag that neither the number nor the type of read data is known. The method in this case creates a new array in the Values parameter with the length equals to FILE_LENGTH - OFFSET, whose items are of the Byte type.
If the value 1 is not entered, then the Values parameter must be set to data type of the array (Array) before calling. Data are than read from the file into the array sequentially according to the data types of this array items.
2 - Flag how to read the text string (String), i.e. how to get its length. If the value je entered, then it's presumed that in the item of the Values array is already a text string of the specified length. From the file so many characters are read into the item how many there are they in the input string (the input string is then overwritten by the same number of characters from the file). In this case the value of the binary 0 shouldn't appear in the file on the place that is referred to such text.
If the value is not entered, then characters from the file are read into the item of the String type until a byte with value 0 is encountered.
Data in the text string form can be read only if the 1 value is not set in the nAttr parameter.
Values(Variant) Variable of the Array type into which binary data are read.
Return value:
Returns the number of read bytes (Caution: not the number of items!). If an error occurred, then the method returns the negative number.
If nAttr=1 is not set, then it is needed to set the data type of the array items before calling the method using VBScript functions CByte, CInt, CLng, CSng, CDbl, etc. By the set data type the method recognizes how many bytes have to be read into the item.
Individual array items are read according to their data type in this matter:
Data type: Number of read bytes from the file:
Byte 1
Integer 2
Long 4
Date 8
Bool 1
Single 4
Double 8
String number of characters + 1 (1 for the character 0, only if nAttr=2 is not set)

This method is not functional in Web panels.
Reading from the file into the Val variable consisting of 3 items. It is read from beginning of the file.
The first byte is stored into the 1st item of the Byte type,
next 4 bytes are stored into the 2nd item of the Long type
and next 5 bytes are stored as a text string (String).
VBScriptSelect and copy to clipboard

Dim Length, Val

Val = Pm.Array1(CByte(0), CLng(0), "12345")
Length = Pm.FileBinaryRead("#data:File.bin", 0, 2, Val)

If Length = 1+4+5 Then
Pm.Debug "Data successfully read. List of items follows:"
Pm.Debug Val, 1
Pm.Debug "Reading data failed! Length=" & Length
End If
Reading from the file into the Val variable. The method sets this variable to the byte array (Array items of the Byte type) with the number according to the file size.
VBScriptSelect and copy to clipboard

Dim Length, Val

Length = Pm.FileBinaryRead("#data:File.bin", 0, 1, Val)
If Length > 0 Then
Pm.Debug "Data successfully read. List of items follows:"
Pm.Debug Val, 1
Pm.Debug "Reading data failed! Length=" & Length
End If

Pm8.01.10: if there was les information in the file than requested, then random values were read.
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
- Pm
- Abs
- Cos
- E
- Exp
- FileBinaryRead
- LN2
- PI
- Pow
- Sin
- Tan
© MICROSYS, spol. s r.o.