FileBinaryRead - method of object Pm

Reading the content of the binary file into the variable of the Array type (into the array of values).
FileBinaryRead(sFile As String, nOffset As Long, nAttr As Long, Values As Variant) As Long
n = Pm.FileBinaryRead(sFile, nOffset, nAttr, Values)
sFile(String) The file name with the path. If a full path is not entered, then it is completed relatively according to the application file 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 then creates a new array in the Values parameter with the length equals to FILE_LENGTH - OFFSET whose items are of 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 is entered, then it's presumed that in the item of the Values array is already a 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 string form can be read only if the value 1 is not set in the nAttr parameter.

Values(Variant) Variable of the Array type into which binary data are read.
Return Values:
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 for Web panels in JavaScript language (and therefore it is not working in Web panels).
Reading from the file into the Val variable consisting of 3 items. It is read from the 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 = Array(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! Lenght=" & 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! Lenght=" & Length
End If
PROMOTIC 8.3.30 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.Tavičská 845/21 703 00 Ostrava-Vítkovice