Gambas Documentation
Como se hace...
Compilación e instalación
Componentes
Controls pictures
Descripciones del Lenguaje
Developer Documentation
Documentacion y Recetas
Documentación del Entorno de Desarrollo
Fragmentos de código
Glosario
Índice del Lenguaje
Abs
Access
ACos
ACosh
Alloc
AND
Ang
APPEND
Array
AS
Asc
Asignación
ASin
ASinh
ATan
ATan2
ATanh
BChg
BClr
BEGINS
Bin$
BREAK
BSet
BTst
BYREF
CASE
CATCH
CBool
Cbr
CByte
CDate
CFloat
Choose
Chr$
CInt
CLASS
CLong
CLOSE
Comp
CONST
Constantes del Lenguaje
CONTINUE
Conv$
COPY
Cos
Cosh
CREATE
CREATE STATIC
CShort
CSng
CStr
Date
DateAdd
DateDiff
Day
DConv$
DEBUG
DEC
Declaracion de Arreglos
Declaración de Constantes
Declaración de Eventos
Declaración de Funciones Externas
Declaración de Métodos
Declaración de Propiedades
Declaración de Variables
Declaración de Variables Locales
DEFAULT
Deg
DFree
DIM
Dir
DIV
DO
ELSE
END
ENDIF
ENDS
END SELECT
END WITH
ENUM
Enumeration declaration
Eof
ERROR
Etiquetas
EVENT
EXEC
Exp
Exp2
Exp10
Expm
EXPORT
Expresión Constante
EXTERN
FALSE
FINALLY
FLUSH
FOR
FOR EACH
Format$
Frac
Free
FUNCTION
GOTO
Hex$
Hour
Html$
Hyp
IF
IN
INC
INPUT
INPUT FROM
InStr
Int
IsAscii
IsBlank
IsBoolean
IsByte
IsDate
IsDigit
IsDir
IsFloat
IsHexa
IsInteger
IsLCase
IsLetter
IsLong
IsNull
IsNumber
IsObject
IsPunct
IsShort
IsSingle
IsSpace
IsString
IsUCase
KILL
LAST
LCase$
Left$
Len
LIBRARY
LIKE
LINE INPUT
LINK
LOCK
Lof
Log
Log2
Log10
Logp
LOOP
LTrim$
Max
ME
Métodos especiales
Mid$
Min
Minute
MKDIR
MOD
Month
MOVE
New
NEXT
NOT
Now
NULL
OPEN
Operadores Aritméticos
Operadores de Asignación
Operadores de Cadena
Operadores Lógicos
OPTIONAL
OR
OUTPUT
OUTPUT TO
Pi
PRINT
PRIVATE
PROCEDURE
PROPERTY
PUBLIC
QUIT
Quote$
Rad
RAISE
Randomize
READ[../../def/stream] _\Stream_
Realloc
REPEAT
Replace$
RETURN
Right$
RInStr
RMDIR
Rnd
Rol
Ror
Round
RTrim$
SConv$
Second
Seek
SELECT
Sgn
Shell$
Shl
Shr
Sin
Sinh
SLEEP
Space$
Split
Sqr
Stat
STATIC
STEP
STOP
STOP EVENT
Str$
String$
StrPtr
SUB
Subst$
SUPER
SWAP
Tan
Tanh
Temp$
THEN
Time
Timer
Tipos de Datos
TO
Trim$
TRUE
TRY
TypeOf
UCase$
UNLOCK
UNTIL
Val
WAIT
WATCH
Week
WeekDay
WEND
WHILE
WITH
WRITE
XOR
Year
LÉEME
Licencia del Wiki
Manual del Wiki
Mensajes de Error
Pendiente de traducción
Registrarse
Repositorio de Aplicaciones
Tutoriales
Últimos cambios

READFlujo _Stream_

READ [ # Stream , ] Variable [ , Length ] READ [ # Pointer , ] Variable [ , Length ]
Lee los Flujo Stream como binarios cuyo tipo el es dado por el tipo de . Las representaciones binarias es utilizada por la instrucción WRITE.

Si el Flujo no esta especificado, entonces se usa la entrada estándar.

Si la Variable es string(cadena), usted puede especificar una longitud que indique el número de bytes a leer, si la longitud es negativa, entonces(- Length) bytes son leídos hasta el final de Flujo.

Si la longitud no es especificada por una cadena, o si la longitud es cero, entonces la longitud de la string es leída del Flujo. La cadena debe haber sido escrita con la instrucción WRITE

Esta instrucción usa las ordenes de bytes del Flujo para leer los datos

Si especificas un Pointer en vez de un Stream, entonces el dato puede ser leído directamente de la dirección de memoria especificada por el puntero.

Si tratas de leer de una dirección de memoria prohibida, obtendrás un error. The interpreter won't crash.

Tenga cuidado con los tipos de datos al agregar a una Variable

El tipo de datos de una Variable es usado para saber que leer exactamente de un Flujo. Tenga en cuenta que no es necesariamente lo que piensas. The datatype of is used to know what to read exactly from the Flujo. Beware that it is not necessarily what you think.

Por ejemplo si usted tiene una referencia anónima de un objeto(ej. Si usa el tipo de dato Object), entonces el tipo de dato de cualquiera de estas propiedades podría llegar a ser Variant, no es un tipo de dato real. Y por lo tanto READ puede leer una variante no esperada.

If you use an object reference whose datatype is declared at compilation time, you won't have this problem.

If you are not sure, the safest way is to use an intermediate local with a well-known datatype.

DIM hStream AS Stream ' The stream
DIM hObject AS Object ' An object with a float property named "Value"
DIM fValue AS Float ' We want to read a float property

' The bad way
READ #hStream, hObject.Value

' The good way
READ #hStream, fValue
hObject.Value = fValue

Example

This example demonstrates how to read a binary file. It will prompt the user to open a wav music file in order to display information from the wav header. It OPEN's the file and then uses SEEK to locate the start of the wav file header. Then we use READ to get the wav header information. Note that we need to read the right number of bytes for each . Hence some of the data types we read are Short and some are Integer. Finally we simple display the information.

PUBLIC Type AS Short
PUBLIC Channels AS Short
PUBLIC SampleRate AS Integer     ' Hz
PUBLIC BytesPerSecond AS Integer ' Bytes
PUBLIC Alignment AS Short
PUBLIC SampleSize AS Short       ' Bits
PUBLIC FileSize AS Integer       ' Bytes
PUBLIC Duration AS Float         ' Seconds

PUBLIC SUB ButtonRead_Click()
  DIM wav AS File
  Dialog.Filter = ["*.wav", "WAVE music files"]
  IF Dialog.OpenFile() THEN RETURN
  ' We need the file size to calculate the duration
  FileSize = Stat(Dialog.Path).Size
  wav = OPEN Dialog.Path FOR READ
  SEEK #wav, 20 ' The info we want starts 20 bytes into the file
  READ #wav, Type
  READ #wav, Channels
  READ #wav, SampleRate
  READ #wav, BytesPerSecond
  READ #wav, Alignment
  READ #wav, SampleSize
  CLOSE #wav
  ' Calc duration in seconds
  Duration = FileSize / BytesPerSecond
  ' Display results
  PRINT "Type                " & Type
  PRINT "Channels            " & Channels
  PRINT "Sample Rate (Hz)    " & SampleRate
  PRINT "Bytes Per Second    " & BytesPerSecond
  PRINT "Alignment           " & Alignment
  PRINT "Sample Size (Bytes) " & SampleSize
  PRINT "File Size (Bytes)   " & FileSize
  PRINT "Duration (Seconds)  " & Duration
CATCH
  PRINT Error.Text
END

Véase también