[Gambas-user] reading files

nando_f at ...951... nando_f at ...951...
Mon Jul 17 21:05:58 CEST 2017


Yes it is possible, I do it.  here is some code (incomplete)

-Nando (Canada)



' top of class file
Public Struct recstruc
  _a as integer
  _b as integer
  _c as integer
end struct


' a function
public function openAfile(filename as string) as file

dim hfile as file
dim arec as recstruc

hfile = open filename for read write create

with arec   'some values to write.
  ._a = 1
  ._b = 22
  ._c = 333
end with

write #hfile, arec as recstruc

'if you position the hfile pointer back to zero, you can...
read #hfile, arec as recstruc

close #hfile

end






--
Open WebMail Project (http://openwebmail.org)


---------- Original Message -----------
From: T Lee Davidson <t.lee.davidson at ...626...>
To: gambas-user at lists.sourceforge.net
Sent: Sun, 16 Jul 2017 12:42:35 -0400
Subject: Re: [Gambas-user] reading files

> On 07/16/2017 06:57 AM, Shane wrote:
> > given this example
> > 
> > PRIVATE SUB BinaryRead(FilePath AS String)
> >    DIM binaryFile AS File
> >    DIM i AS Integer
> >    DIM b AS Byte
> >    DIM s AS Short
> >    DIM s1 AS String
> >    DIM s2 AS String
> >    ' Read binary file
> >    binaryFile = OPEN FilePath FOR READ
> >    READ #binaryFile, i
> >    READ #binaryFile, b
> >    READ #binaryFile, s
> >    READ #binaryFile, s1
> >    READ #binaryFile, s2
> >    CLOSE #binaryFile
> >    ' Display results
> >    PRINT i
> >    PRINT b
> >    PRINT s
> >    PRINT s1
> >    PRINT s2
> > END
> > 
> > 
> > is there a way for gambas to read a struct of all these variables
> > in one read ?
> >
> 
> You may have hinted at the solution within your question. Have you considered 
> using a Structure?
> 
> http://gambaswiki.org/wiki/lang/read :
> "... reads the stream Stream as binary data whose type is specified by the 
> Datatype argument."
> 
> "The returned datatype can be one of the following: NULL, Boolean, Byte, Short,
>  Integer, Long, Pointer, Single, Float, Date, String, Variant, any Array,
>  Collection or structure."
> 
> http://gambaswiki.org/wiki/lang/structdecl
> 
> -- 
> Lee
> 
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list