[Gambas-user] don't know how to read
Benoît Minisini
gambas at ...1...
Tue Jan 28 11:36:37 CET 2003
Le Lundi 27 Janvier 2003 00:01, Jochen Georges a écrit :
> hello
>
> but i got an error message:
> type mismatched, wanted file, got string instead
>
> but the encyclopedeia sais:
> ------------------------------------
> READ variable [, legth]
> reads the standard output as binary data whose type is given by the
> type of the variable ...
> if variable is a string ...
> ------------------------------------
> _and_
>
> READ file [,length]
> ------------------------------------
>
>
> the code that throws the error:
> PRIVATE inttext AS String
>
> PUBLIC SUB _new()
> intext = "hello"
> END
>
> PUBLIC SUB Button1_Click()
> outtext = Read(intext)
> END
>
>
>
> thanks for any hint
>
>
> beste gruesse
> jochen
>
Hi Jochen,
Here is the contents of the encyclopaedia :
READ Variable [ , Length ]
Reads the standard output as binary data whose type is given by the type of
the variable. The binary representation is the one used by the WRITE
instruction.
If Variable is a string, you can specify a length that indicates the number of
bytes to read. If no length is specified for a string, it is is read from the
stream.
READ #File , Variable [ , Length ]
Same as above, except that the data are read from the stream File.
READ is used for reading binary data from a stream. You cannot use it for
reading from a string.
To read an integer, you do the following :
DIM iInteger AS Integer
OPEN ... AS #hFile
...
READ #hFile, iInteger
PRINT "I have read "; iInteger
To read N bytes and put them in a string :
DIM sString AS String
DIM N AS Integer
OPEN ... AS #hFile
...
READ #hFile, sString, N
PRINT "I have read "; sString
To read a string previously written with WRITE, you just do :
READ #hFile, sString
without the last parameter, because the length of the string is stored in the
stream by WRITE.
Hope it is clearer now.
--
Benoît Minisini
mailto:gambas at ...1...
More information about the User
mailing list