reading files

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

reading files

Shane-2
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 ?


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

T Lee Davidson
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

nando_f
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 <[hidden email]>
To: [hidden email]
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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Shane-2
i don't know what i am doing wrong

Public Struct ID3v1_TAG              '(128 bytes)
      Tag[3] As String               'always TAG
      Title[30] As String             'title, 30 characters
      Artist[30] As String           'artist, 30 characters
      Album[30] As String           'album, 30 characters
      Year[4] As String              'year, 4 characters
      Comment[30] As String          'comment, 30 characters (or 28 if
track# included)
      Genre As Byte                   'genre, 255 for none defined
End Struct


Private Sub GetID3v1(File As String)
     Dim IDtag As ID3v1_TAG
     Dim hfile As File

     hfile = Open File For Read

         '
         'read the tag
         ' seek to end of less tag size

         Read #hfile, IDtag, ID3v1_TAG

here i get IDtag is NULL


On 18/07/17 05:05, [hidden email] wrote:

> 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 <[hidden email]>
> To: [hidden email]
> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
> ------- End of Original Message -------
>
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

nando_f
I think
        Read #hfile, IDtag, ID3v1_TAG
should be
        Read #hfile, IDtag as ID3v1_TAG


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


---------- Original Message -----------
From: Shane <[hidden email]>
To: [hidden email]
Sent: Tue, 18 Jul 2017 10:50:43 +1000
Subject: Re: [Gambas-user] reading files

> i don't know what i am doing wrong
>
> Public Struct ID3v1_TAG              '(128 bytes)
>       Tag[3] As String               'always TAG
>       Title[30] As String             'title, 30 characters
>       Artist[30] As String           'artist, 30 characters
>       Album[30] As String           'album, 30 characters
>       Year[4] As String              'year, 4 characters
>       Comment[30] As String          'comment, 30 characters (or 28 if
> track# included)
>       Genre As Byte                   'genre, 255 for none defined
> End Struct
>
> Private Sub GetID3v1(File As String)
>      Dim IDtag As ID3v1_TAG
>      Dim hfile As File
>
>      hfile = Open File For Read
>
>          '
>          'read the tag
>          ' seek to end of less tag size
>
>          Read #hfile, IDtag, ID3v1_TAG
>
> here i get IDtag is NULL
>
> On 18/07/17 05:05, [hidden email] wrote:
> > 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 <[hidden email]>
> > To: [hidden email]
> > 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
> >> [hidden email]
> >> https://lists.sourceforge.net/lists/listinfo/gambas-user
> > ------- End of Original Message -------
> >
> >
> > ------------------------------------------------------------------------------
> > 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
> > [hidden email]
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Shane-2
I am very confused from the docs

_Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_

_Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_

so wouldn't it be_
_

IDtag = read #hfile  as ID3v1_TAG  ?

with doesn't work by the way



On 18/07/17 12:44, [hidden email] wrote:

> I think
>          Read #hfile, IDtag, ID3v1_TAG
> should be
>          Read #hfile, IDtag as ID3v1_TAG
>
>
> --
> Open WebMail Project (http://openwebmail.org)
>
>
> ---------- Original Message -----------
> From: Shane <[hidden email]>
> To: [hidden email]
> Sent: Tue, 18 Jul 2017 10:50:43 +1000
> Subject: Re: [Gambas-user] reading files
>
>> i don't know what i am doing wrong
>>
>> Public Struct ID3v1_TAG              '(128 bytes)
>>        Tag[3] As String               'always TAG
>>        Title[30] As String             'title, 30 characters
>>        Artist[30] As String           'artist, 30 characters
>>        Album[30] As String           'album, 30 characters
>>        Year[4] As String              'year, 4 characters
>>        Comment[30] As String          'comment, 30 characters (or 28 if
>> track# included)
>>        Genre As Byte                   'genre, 255 for none defined
>> End Struct
>>
>> Private Sub GetID3v1(File As String)
>>       Dim IDtag As ID3v1_TAG
>>       Dim hfile As File
>>
>>       hfile = Open File For Read
>>
>>           '
>>           'read the tag
>>           ' seek to end of less tag size
>>
>>           Read #hfile, IDtag, ID3v1_TAG
>>
>> here i get IDtag is NULL
>>
>> On 18/07/17 05:05, [hidden email] wrote:
>>> 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 <[hidden email]>
>>> To: [hidden email]
>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>> ------- End of Original Message -------
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> ------------------------------------------------------------------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
> ------- End of Original Message -------
>
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Gianluigi
Why do not you take a moment of rest and read what Tobias Boege recommend
me in the discussion [0] I told you here [1]?

[0]
http://gambas.8142.n7.nabble.com/Random-access-files-with-fixed-length-string-td50880.html
[1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html

2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:

> I am very confused from the docs
>
> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>
> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>
> so wouldn't it be_
> _
>
> IDtag = read #hfile  as ID3v1_TAG  ?
>
> with doesn't work by the way
>
>
>
> On 18/07/17 12:44, [hidden email] wrote:
>
>> I think
>>          Read #hfile, IDtag, ID3v1_TAG
>> should be
>>          Read #hfile, IDtag as ID3v1_TAG
>>
>>
>> --
>> Open WebMail Project (http://openwebmail.org)
>>
>>
>> ---------- Original Message -----------
>> From: Shane <[hidden email]>
>> To: [hidden email]
>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>> Subject: Re: [Gambas-user] reading files
>>
>> i don't know what i am doing wrong
>>>
>>> Public Struct ID3v1_TAG              '(128 bytes)
>>>        Tag[3] As String               'always TAG
>>>        Title[30] As String             'title, 30 characters
>>>        Artist[30] As String           'artist, 30 characters
>>>        Album[30] As String           'album, 30 characters
>>>        Year[4] As String              'year, 4 characters
>>>        Comment[30] As String          'comment, 30 characters (or 28 if
>>> track# included)
>>>        Genre As Byte                   'genre, 255 for none defined
>>> End Struct
>>>
>>> Private Sub GetID3v1(File As String)
>>>       Dim IDtag As ID3v1_TAG
>>>       Dim hfile As File
>>>
>>>       hfile = Open File For Read
>>>
>>>           '
>>>           'read the tag
>>>           ' seek to end of less tag size
>>>
>>>           Read #hfile, IDtag, ID3v1_TAG
>>>
>>> here i get IDtag is NULL
>>>
>>> On 18/07/17 05:05, [hidden email] wrote:
>>>
>>>> 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 <[hidden email]>
>>>> To: [hidden email]
>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>> ------- End of Original Message -------
>>>>
>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>> ------- End of Original Message -------
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
> ------------------------------------------------------------
> ------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Shane-2
thank you Gian i did take a rest and read but alas it did not help

as far as i see it he is saying don't use binary file for fixed length
strings

but as this is an mp3 file tag witch i have no control i am doomed



On 18/07/17 19:22, Gianluigi wrote:

> Why do not you take a moment of rest and read what Tobias Boege recommend
> me in the discussion [0] I told you here [1]?
>
> [0]
> http://gambas.8142.n7.nabble.com/Random-access-files-with-fixed-length-string-td50880.html
> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>
> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>
>> I am very confused from the docs
>>
>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>
>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>
>> so wouldn't it be_
>> _
>>
>> IDtag = read #hfile  as ID3v1_TAG  ?
>>
>> with doesn't work by the way
>>
>>
>>
>> On 18/07/17 12:44, [hidden email] wrote:
>>
>>> I think
>>>           Read #hfile, IDtag, ID3v1_TAG
>>> should be
>>>           Read #hfile, IDtag as ID3v1_TAG
>>>
>>>
>>> --
>>> Open WebMail Project (http://openwebmail.org)
>>>
>>>
>>> ---------- Original Message -----------
>>> From: Shane <[hidden email]>
>>> To: [hidden email]
>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>> Subject: Re: [Gambas-user] reading files
>>>
>>> i don't know what i am doing wrong
>>>> Public Struct ID3v1_TAG              '(128 bytes)
>>>>         Tag[3] As String               'always TAG
>>>>         Title[30] As String             'title, 30 characters
>>>>         Artist[30] As String           'artist, 30 characters
>>>>         Album[30] As String           'album, 30 characters
>>>>         Year[4] As String              'year, 4 characters
>>>>         Comment[30] As String          'comment, 30 characters (or 28 if
>>>> track# included)
>>>>         Genre As Byte                   'genre, 255 for none defined
>>>> End Struct
>>>>
>>>> Private Sub GetID3v1(File As String)
>>>>        Dim IDtag As ID3v1_TAG
>>>>        Dim hfile As File
>>>>
>>>>        hfile = Open File For Read
>>>>
>>>>            '
>>>>            'read the tag
>>>>            ' seek to end of less tag size
>>>>
>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>
>>>> here i get IDtag is NULL
>>>>
>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>
>>>>> 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 <[hidden email]>
>>>>> To: [hidden email]
>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>> ------- End of Original Message -------
>>>>>
>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>> ------- End of Original Message -------
>>>
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Gianluigi
You can take a look at our Italian wiki [0][1][2] using Google Translate.
You can also subscribe and ask a question in English, I do not understand
mp3, but there is someone who understands it.

Regards
Gianluigi

[0]
http://www.gambas-it.org/wiki/index.php?title=Estrarre_informazioni_e_TAG_da_un_file_MP3_con_le_sole_funzioni_di_Gambas
[1]
http://www.gambas-it.org/wiki/index.php?title=Guide_della_comunit%C3%A0#Gestione_dei_dati_audio_e_dei_file_audio
[2]
http://www.gambas-it.org/wiki/index.php?title=Guide_della_comunit%C3%A0#Struttur

2017-07-19 6:33 GMT+02:00 Shane <[hidden email]>:

> thank you Gian i did take a rest and read but alas it did not help
>
> as far as i see it he is saying don't use binary file for fixed length
> strings
>
> but as this is an mp3 file tag witch i have no control i am doomed
>
>
>
> On 18/07/17 19:22, Gianluigi wrote:
>
>> Why do not you take a moment of rest and read what Tobias Boege recommend
>> me in the discussion [0] I told you here [1]?
>>
>> [0]
>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>> xed-length-string-td50880.html
>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>
>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>
>> I am very confused from the docs
>>>
>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>
>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>
>>> so wouldn't it be_
>>> _
>>>
>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>
>>> with doesn't work by the way
>>>
>>>
>>>
>>> On 18/07/17 12:44, [hidden email] wrote:
>>>
>>> I think
>>>>           Read #hfile, IDtag, ID3v1_TAG
>>>> should be
>>>>           Read #hfile, IDtag as ID3v1_TAG
>>>>
>>>>
>>>> --
>>>> Open WebMail Project (http://openwebmail.org)
>>>>
>>>>
>>>> ---------- Original Message -----------
>>>> From: Shane <[hidden email]>
>>>> To: [hidden email]
>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>> Subject: Re: [Gambas-user] reading files
>>>>
>>>> i don't know what i am doing wrong
>>>>
>>>>> Public Struct ID3v1_TAG              '(128 bytes)
>>>>>         Tag[3] As String               'always TAG
>>>>>         Title[30] As String             'title, 30 characters
>>>>>         Artist[30] As String           'artist, 30 characters
>>>>>         Album[30] As String           'album, 30 characters
>>>>>         Year[4] As String              'year, 4 characters
>>>>>         Comment[30] As String          'comment, 30 characters (or 28
>>>>> if
>>>>> track# included)
>>>>>         Genre As Byte                   'genre, 255 for none defined
>>>>> End Struct
>>>>>
>>>>> Private Sub GetID3v1(File As String)
>>>>>        Dim IDtag As ID3v1_TAG
>>>>>        Dim hfile As File
>>>>>
>>>>>        hfile = Open File For Read
>>>>>
>>>>>            '
>>>>>            'read the tag
>>>>>            ' seek to end of less tag size
>>>>>
>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>
>>>>> here i get IDtag is NULL
>>>>>
>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>
>>>>> 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 <[hidden email]>
>>>>>> To: [hidden email]
>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------- End of Original Message -------
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>> ------- End of Original Message -------
>>>>
>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
> ------------------------------------------------------------
> ------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Tony Morehen
In reply to this post by Shane-2
I've attached an archive containing the code I use to read v1 and v2 MP3
tags and other MP3 info including bitrates (fixed and VBR), sampling
rates and number of channels.  v1 tags are pretty staightforward to read
if you don't try to read the structure directly, but by each element of
the structure at a time.  Some tips:

1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can be
read directly from the stream. ie  (4 byte Integer) = Read #Stream As
Integer.  Gambas can handle little endian/big endian issues.

2) Fixed length strings must be handled in a two stage process. First,
the required string length number of bytes is read into a byte array.  
This byte array is then converted to a string. Sample code:

   Dim Bytes As New Byte[StringLength]
   Bytes.Read(Stream)
   FixedString = Bytes.ToString()

Note: Bytes.ToString stops the string conversion at the first null or at
the end of the array.  Therfore, you don't have to worry about
null-terminated strings.

v2 tags are more complicated, particularly since the tags can be ascii,
either kind of utf16, or utf8 encoding.  The code I sent has been tested
with over 10,000 mp3 files has seems to have no issues.


On 2017-07-19 12:33 AM, Shane wrote:

> thank you Gian i did take a rest and read but alas it did not help
>
> as far as i see it he is saying don't use binary file for fixed length
> strings
>
> but as this is an mp3 file tag witch i have no control i am doomed
>
>
>
> On 18/07/17 19:22, Gianluigi wrote:
>> Why do not you take a moment of rest and read what Tobias Boege
>> recommend
>> me in the discussion [0] I told you here [1]?
>>
>> [0]
>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fixed-length-string-td50880.html 
>>
>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>
>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>
>>> I am very confused from the docs
>>>
>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>
>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>
>>> so wouldn't it be_
>>> _
>>>
>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>
>>> with doesn't work by the way
>>>
>>>
>>>
>>> On 18/07/17 12:44, [hidden email] wrote:
>>>
>>>> I think
>>>>           Read #hfile, IDtag, ID3v1_TAG
>>>> should be
>>>>           Read #hfile, IDtag as ID3v1_TAG
>>>>
>>>>
>>>> --
>>>> Open WebMail Project (http://openwebmail.org)
>>>>
>>>>
>>>> ---------- Original Message -----------
>>>> From: Shane <[hidden email]>
>>>> To: [hidden email]
>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>> Subject: Re: [Gambas-user] reading files
>>>>
>>>> i don't know what i am doing wrong
>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>         Tag[3] As String               'always TAG
>>>>>         Title[30] As String             'title, 30 characters
>>>>>         Artist[30] As String           'artist, 30 characters
>>>>>         Album[30] As String           'album, 30 characters
>>>>>         Year[4] As String              'year, 4 characters
>>>>>         Comment[30] As String          'comment, 30 characters (or
>>>>> 28 if
>>>>> track# included)
>>>>>         Genre As Byte                   'genre, 255 for none defined
>>>>> End Struct
>>>>>
>>>>> Private Sub GetID3v1(File As String)
>>>>>        Dim IDtag As ID3v1_TAG
>>>>>        Dim hfile As File
>>>>>
>>>>>        hfile = Open File For Read
>>>>>
>>>>>            '
>>>>>            'read the tag
>>>>>            ' seek to end of less tag size
>>>>>
>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>
>>>>> here i get IDtag is NULL
>>>>>
>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>
>>>>>> 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 <[hidden email]>
>>>>>> To: [hidden email]
>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>> ------- End of Original Message -------
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>> ------- End of Original Message -------
>>>>
>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>> ------------------------------------------------------------------------------
>>
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
> ------------------------------------------------------------------------------
>
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user

Mp3Tag.tar.gz (27K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Gianluigi
A very interesting work 👍

Regards
Gianluigi

2017-07-19 14:34 GMT+02:00 Tony Morehen <[hidden email]>:

> I've attached an archive containing the code I use to read v1 and v2 MP3
> tags and other MP3 info including bitrates (fixed and VBR), sampling rates
> and number of channels.  v1 tags are pretty staightforward to read if you
> don't try to read the structure directly, but by each element of the
> structure at a time.  Some tips:
>
> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can be
> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
> Integer.  Gambas can handle little endian/big endian issues.
>
> 2) Fixed length strings must be handled in a two stage process. First, the
> required string length number of bytes is read into a byte array.  This
> byte array is then converted to a string. Sample code:
>
>   Dim Bytes As New Byte[StringLength]
>   Bytes.Read(Stream)
>   FixedString = Bytes.ToString()
>
> Note: Bytes.ToString stops the string conversion at the first null or at
> the end of the array.  Therfore, you don't have to worry about
> null-terminated strings.
>
> v2 tags are more complicated, particularly since the tags can be ascii,
> either kind of utf16, or utf8 encoding.  The code I sent has been tested
> with over 10,000 mp3 files has seems to have no issues.
>
>
> On 2017-07-19 12:33 AM, Shane wrote:
>
>> thank you Gian i did take a rest and read but alas it did not help
>>
>> as far as i see it he is saying don't use binary file for fixed length
>> strings
>>
>> but as this is an mp3 file tag witch i have no control i am doomed
>>
>>
>>
>> On 18/07/17 19:22, Gianluigi wrote:
>>
>>> Why do not you take a moment of rest and read what Tobias Boege recommend
>>> me in the discussion [0] I told you here [1]?
>>>
>>> [0]
>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>> xed-length-string-td50880.html
>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>
>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>
>>> I am very confused from the docs
>>>>
>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>
>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>
>>>> so wouldn't it be_
>>>> _
>>>>
>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>
>>>> with doesn't work by the way
>>>>
>>>>
>>>>
>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>
>>>> I think
>>>>>           Read #hfile, IDtag, ID3v1_TAG
>>>>> should be
>>>>>           Read #hfile, IDtag as ID3v1_TAG
>>>>>
>>>>>
>>>>> --
>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>
>>>>>
>>>>> ---------- Original Message -----------
>>>>> From: Shane <[hidden email]>
>>>>> To: [hidden email]
>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>> Subject: Re: [Gambas-user] reading files
>>>>>
>>>>> i don't know what i am doing wrong
>>>>>
>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>         Tag[3] As String               'always TAG
>>>>>>         Title[30] As String             'title, 30 characters
>>>>>>         Artist[30] As String           'artist, 30 characters
>>>>>>         Album[30] As String           'album, 30 characters
>>>>>>         Year[4] As String              'year, 4 characters
>>>>>>         Comment[30] As String          'comment, 30 characters (or 28
>>>>>> if
>>>>>> track# included)
>>>>>>         Genre As Byte                   'genre, 255 for none defined
>>>>>> End Struct
>>>>>>
>>>>>> Private Sub GetID3v1(File As String)
>>>>>>        Dim IDtag As ID3v1_TAG
>>>>>>        Dim hfile As File
>>>>>>
>>>>>>        hfile = Open File For Read
>>>>>>
>>>>>>            '
>>>>>>            'read the tag
>>>>>>            ' seek to end of less tag size
>>>>>>
>>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>>
>>>>>> here i get IDtag is NULL
>>>>>>
>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>
>>>>>> 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 <[hidden email]>
>>>>>>> To: [hidden email]
>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>> ------- End of Original Message -------
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------- End of Original Message -------
>>>>>
>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>> ------------------------------------------------------------------------------
>>>
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
> ------------------------------------------------------------
> ------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Shane-2
In reply to this post by Tony Morehen
thanks tony sounds like just what i needed i will take a look

cheers



On 19/07/17 22:34, Tony Morehen wrote:

> I've attached an archive containing the code I use to read v1 and v2
> MP3 tags and other MP3 info including bitrates (fixed and VBR),
> sampling rates and number of channels.  v1 tags are pretty
> staightforward to read if you don't try to read the structure
> directly, but by each element of the structure at a time.  Some tips:
>
> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can
> be read directly from the stream. ie  (4 byte Integer) = Read #Stream
> As Integer.  Gambas can handle little endian/big endian issues.
>
> 2) Fixed length strings must be handled in a two stage process. First,
> the required string length number of bytes is read into a byte array.  
> This byte array is then converted to a string. Sample code:
>
>   Dim Bytes As New Byte[StringLength]
>   Bytes.Read(Stream)
>   FixedString = Bytes.ToString()
>
> Note: Bytes.ToString stops the string conversion at the first null or
> at the end of the array.  Therfore, you don't have to worry about
> null-terminated strings.
>
> v2 tags are more complicated, particularly since the tags can be
> ascii, either kind of utf16, or utf8 encoding.  The code I sent has
> been tested with over 10,000 mp3 files has seems to have no issues.
>
>
> On 2017-07-19 12:33 AM, Shane wrote:
>> thank you Gian i did take a rest and read but alas it did not help
>>
>> as far as i see it he is saying don't use binary file for fixed
>> length strings
>>
>> but as this is an mp3 file tag witch i have no control i am doomed
>>
>>
>>
>> On 18/07/17 19:22, Gianluigi wrote:
>>> Why do not you take a moment of rest and read what Tobias Boege
>>> recommend
>>> me in the discussion [0] I told you here [1]?
>>>
>>> [0]
>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fixed-length-string-td50880.html 
>>>
>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>
>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>
>>>> I am very confused from the docs
>>>>
>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>
>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>
>>>> so wouldn't it be_
>>>> _
>>>>
>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>
>>>> with doesn't work by the way
>>>>
>>>>
>>>>
>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>
>>>>> I think
>>>>>           Read #hfile, IDtag, ID3v1_TAG
>>>>> should be
>>>>>           Read #hfile, IDtag as ID3v1_TAG
>>>>>
>>>>>
>>>>> --
>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>
>>>>>
>>>>> ---------- Original Message -----------
>>>>> From: Shane <[hidden email]>
>>>>> To: [hidden email]
>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>> Subject: Re: [Gambas-user] reading files
>>>>>
>>>>> i don't know what i am doing wrong
>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>         Tag[3] As String               'always TAG
>>>>>>         Title[30] As String             'title, 30 characters
>>>>>>         Artist[30] As String           'artist, 30 characters
>>>>>>         Album[30] As String           'album, 30 characters
>>>>>>         Year[4] As String              'year, 4 characters
>>>>>>         Comment[30] As String          'comment, 30 characters
>>>>>> (or 28 if
>>>>>> track# included)
>>>>>>         Genre As Byte                   'genre, 255 for none defined
>>>>>> End Struct
>>>>>>
>>>>>> Private Sub GetID3v1(File As String)
>>>>>>        Dim IDtag As ID3v1_TAG
>>>>>>        Dim hfile As File
>>>>>>
>>>>>>        hfile = Open File For Read
>>>>>>
>>>>>>            '
>>>>>>            'read the tag
>>>>>>            ' seek to end of less tag size
>>>>>>
>>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>>
>>>>>> here i get IDtag is NULL
>>>>>>
>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>
>>>>>>> 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 <[hidden email]>
>>>>>>> To: [hidden email]
>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>> ------- End of Original Message -------
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>> ------- End of Original Message -------
>>>>>
>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>> ------------------------------------------------------------------------------
>>>
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>>
>> ------------------------------------------------------------------------------
>>
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user

------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Gianluigi
Right ... and a look here too [0]

Ciao :)
Gianluigi

[0] http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#msg41793

2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:

> thanks tony sounds like just what i needed i will take a look
>
> cheers
>
>
>
> On 19/07/17 22:34, Tony Morehen wrote:
>
>> I've attached an archive containing the code I use to read v1 and v2 MP3
>> tags and other MP3 info including bitrates (fixed and VBR), sampling rates
>> and number of channels.  v1 tags are pretty staightforward to read if you
>> don't try to read the structure directly, but by each element of the
>> structure at a time.  Some tips:
>>
>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can be
>> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
>> Integer.  Gambas can handle little endian/big endian issues.
>>
>> 2) Fixed length strings must be handled in a two stage process. First,
>> the required string length number of bytes is read into a byte array.  This
>> byte array is then converted to a string. Sample code:
>>
>>   Dim Bytes As New Byte[StringLength]
>>   Bytes.Read(Stream)
>>   FixedString = Bytes.ToString()
>>
>> Note: Bytes.ToString stops the string conversion at the first null or at
>> the end of the array.  Therfore, you don't have to worry about
>> null-terminated strings.
>>
>> v2 tags are more complicated, particularly since the tags can be ascii,
>> either kind of utf16, or utf8 encoding.  The code I sent has been tested
>> with over 10,000 mp3 files has seems to have no issues.
>>
>>
>> On 2017-07-19 12:33 AM, Shane wrote:
>>
>>> thank you Gian i did take a rest and read but alas it did not help
>>>
>>> as far as i see it he is saying don't use binary file for fixed length
>>> strings
>>>
>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>
>>>
>>>
>>> On 18/07/17 19:22, Gianluigi wrote:
>>>
>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>> recommend
>>>> me in the discussion [0] I told you here [1]?
>>>>
>>>> [0]
>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>> xed-length-string-td50880.html
>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>
>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>
>>>> I am very confused from the docs
>>>>>
>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>
>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>
>>>>> so wouldn't it be_
>>>>> _
>>>>>
>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>
>>>>> with doesn't work by the way
>>>>>
>>>>>
>>>>>
>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>
>>>>> I think
>>>>>>           Read #hfile, IDtag, ID3v1_TAG
>>>>>> should be
>>>>>>           Read #hfile, IDtag as ID3v1_TAG
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>
>>>>>>
>>>>>> ---------- Original Message -----------
>>>>>> From: Shane <[hidden email]>
>>>>>> To: [hidden email]
>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>
>>>>>> i don't know what i am doing wrong
>>>>>>
>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>         Tag[3] As String               'always TAG
>>>>>>>         Title[30] As String             'title, 30 characters
>>>>>>>         Artist[30] As String           'artist, 30 characters
>>>>>>>         Album[30] As String           'album, 30 characters
>>>>>>>         Year[4] As String              'year, 4 characters
>>>>>>>         Comment[30] As String          'comment, 30 characters (or
>>>>>>> 28 if
>>>>>>> track# included)
>>>>>>>         Genre As Byte                   'genre, 255 for none defined
>>>>>>> End Struct
>>>>>>>
>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>        Dim IDtag As ID3v1_TAG
>>>>>>>        Dim hfile As File
>>>>>>>
>>>>>>>        hfile = Open File For Read
>>>>>>>
>>>>>>>            '
>>>>>>>            'read the tag
>>>>>>>            ' seek to end of less tag size
>>>>>>>
>>>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>>>
>>>>>>> here i get IDtag is NULL
>>>>>>>
>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>
>>>>>>> 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 <[hidden email]>
>>>>>>>> To: [hidden email]
>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>> ------- End of Original Message -------
>>>>>>>>
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>>> ------------------
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------- End of Original Message -------
>>>>>>
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>>
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>>
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
> ------------------------------------------------------------
> ------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Shane-2
yep can't use structs have to do like tony's code works perfect thanks
again tony

p.s is this your code ?



On 20/07/17 19:56, Gianluigi wrote:

> Right ... and a look here too [0]
>
> Ciao :)
> Gianluigi
>
> [0] http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#msg41793
>
> 2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:
>
>> thanks tony sounds like just what i needed i will take a look
>>
>> cheers
>>
>>
>>
>> On 19/07/17 22:34, Tony Morehen wrote:
>>
>>> I've attached an archive containing the code I use to read v1 and v2 MP3
>>> tags and other MP3 info including bitrates (fixed and VBR), sampling rates
>>> and number of channels.  v1 tags are pretty staightforward to read if you
>>> don't try to read the structure directly, but by each element of the
>>> structure at a time.  Some tips:
>>>
>>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can be
>>> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
>>> Integer.  Gambas can handle little endian/big endian issues.
>>>
>>> 2) Fixed length strings must be handled in a two stage process. First,
>>> the required string length number of bytes is read into a byte array.  This
>>> byte array is then converted to a string. Sample code:
>>>
>>>    Dim Bytes As New Byte[StringLength]
>>>    Bytes.Read(Stream)
>>>    FixedString = Bytes.ToString()
>>>
>>> Note: Bytes.ToString stops the string conversion at the first null or at
>>> the end of the array.  Therfore, you don't have to worry about
>>> null-terminated strings.
>>>
>>> v2 tags are more complicated, particularly since the tags can be ascii,
>>> either kind of utf16, or utf8 encoding.  The code I sent has been tested
>>> with over 10,000 mp3 files has seems to have no issues.
>>>
>>>
>>> On 2017-07-19 12:33 AM, Shane wrote:
>>>
>>>> thank you Gian i did take a rest and read but alas it did not help
>>>>
>>>> as far as i see it he is saying don't use binary file for fixed length
>>>> strings
>>>>
>>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>>
>>>>
>>>>
>>>> On 18/07/17 19:22, Gianluigi wrote:
>>>>
>>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>>> recommend
>>>>> me in the discussion [0] I told you here [1]?
>>>>>
>>>>> [0]
>>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>>> xed-length-string-td50880.html
>>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>>
>>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>>
>>>>> I am very confused from the docs
>>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>>
>>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>>
>>>>>> so wouldn't it be_
>>>>>> _
>>>>>>
>>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>>
>>>>>> with doesn't work by the way
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>>
>>>>>> I think
>>>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>>> should be
>>>>>>>            Read #hfile, IDtag as ID3v1_TAG
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>>
>>>>>>>
>>>>>>> ---------- Original Message -----------
>>>>>>> From: Shane <[hidden email]>
>>>>>>> To: [hidden email]
>>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>>
>>>>>>> i don't know what i am doing wrong
>>>>>>>
>>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>>          Tag[3] As String               'always TAG
>>>>>>>>          Title[30] As String             'title, 30 characters
>>>>>>>>          Artist[30] As String           'artist, 30 characters
>>>>>>>>          Album[30] As String           'album, 30 characters
>>>>>>>>          Year[4] As String              'year, 4 characters
>>>>>>>>          Comment[30] As String          'comment, 30 characters (or
>>>>>>>> 28 if
>>>>>>>> track# included)
>>>>>>>>          Genre As Byte                   'genre, 255 for none defined
>>>>>>>> End Struct
>>>>>>>>
>>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>>         Dim IDtag As ID3v1_TAG
>>>>>>>>         Dim hfile As File
>>>>>>>>
>>>>>>>>         hfile = Open File For Read
>>>>>>>>
>>>>>>>>             '
>>>>>>>>             'read the tag
>>>>>>>>             ' seek to end of less tag size
>>>>>>>>
>>>>>>>>             Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>
>>>>>>>> here i get IDtag is NULL
>>>>>>>>
>>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>>
>>>>>>>> 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 <[hidden email]>
>>>>>>>>> To: [hidden email]
>>>>>>>>> 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
>>>>>>>>>> [hidden email]
>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>
>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>>> ------------------
>>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>> ------------------
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>> ------- End of Original Message -------
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------------------------------------------------------------------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>>
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Gianluigi
2017-07-20 12:09 GMT+02:00 Shane <[hidden email]>:

> yep can't use structs have to do like tony's code works perfect thanks
> again tony
>

mmmmh are you sure?


>
> p.s is this your code ?
>

No, but you can easily see who wrote it :)


>
>
>
> On 20/07/17 19:56, Gianluigi wrote:
>
>> Right ... and a look here too [0]
>>
>> Ciao :)
>> Gianluigi
>>
>> [0] http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#msg41793
>>
>> 2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:
>>
>> thanks tony sounds like just what i needed i will take a look
>>>
>>> cheers
>>>
>>>
>>>
>>> On 19/07/17 22:34, Tony Morehen wrote:
>>>
>>> I've attached an archive containing the code I use to read v1 and v2 MP3
>>>> tags and other MP3 info including bitrates (fixed and VBR), sampling
>>>> rates
>>>> and number of channels.  v1 tags are pretty staightforward to read if
>>>> you
>>>> don't try to read the structure directly, but by each element of the
>>>> structure at a time.  Some tips:
>>>>
>>>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can be
>>>> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
>>>> Integer.  Gambas can handle little endian/big endian issues.
>>>>
>>>> 2) Fixed length strings must be handled in a two stage process. First,
>>>> the required string length number of bytes is read into a byte array.
>>>> This
>>>> byte array is then converted to a string. Sample code:
>>>>
>>>>    Dim Bytes As New Byte[StringLength]
>>>>    Bytes.Read(Stream)
>>>>    FixedString = Bytes.ToString()
>>>>
>>>> Note: Bytes.ToString stops the string conversion at the first null or at
>>>> the end of the array.  Therfore, you don't have to worry about
>>>> null-terminated strings.
>>>>
>>>> v2 tags are more complicated, particularly since the tags can be ascii,
>>>> either kind of utf16, or utf8 encoding.  The code I sent has been tested
>>>> with over 10,000 mp3 files has seems to have no issues.
>>>>
>>>>
>>>> On 2017-07-19 12:33 AM, Shane wrote:
>>>>
>>>> thank you Gian i did take a rest and read but alas it did not help
>>>>>
>>>>> as far as i see it he is saying don't use binary file for fixed length
>>>>> strings
>>>>>
>>>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>>>
>>>>>
>>>>>
>>>>> On 18/07/17 19:22, Gianluigi wrote:
>>>>>
>>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>>>> recommend
>>>>>> me in the discussion [0] I told you here [1]?
>>>>>>
>>>>>> [0]
>>>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>>>> xed-length-string-td50880.html
>>>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>>>
>>>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>>>
>>>>>> I am very confused from the docs
>>>>>>
>>>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>>>
>>>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>>>
>>>>>>> so wouldn't it be_
>>>>>>> _
>>>>>>>
>>>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>>>
>>>>>>> with doesn't work by the way
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>>>
>>>>>>> I think
>>>>>>>
>>>>>>>>            Read #hfile, IDtag, ID3v1_TAG
>>>>>>>> should be
>>>>>>>>            Read #hfile, IDtag as ID3v1_TAG
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>>>
>>>>>>>>
>>>>>>>> ---------- Original Message -----------
>>>>>>>> From: Shane <[hidden email]>
>>>>>>>> To: [hidden email]
>>>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>>>
>>>>>>>> i don't know what i am doing wrong
>>>>>>>>
>>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>>>          Tag[3] As String               'always TAG
>>>>>>>>>          Title[30] As String             'title, 30 characters
>>>>>>>>>          Artist[30] As String           'artist, 30 characters
>>>>>>>>>          Album[30] As String           'album, 30 characters
>>>>>>>>>          Year[4] As String              'year, 4 characters
>>>>>>>>>          Comment[30] As String          'comment, 30 characters (or
>>>>>>>>> 28 if
>>>>>>>>> track# included)
>>>>>>>>>          Genre As Byte                   'genre, 255 for none
>>>>>>>>> defined
>>>>>>>>> End Struct
>>>>>>>>>
>>>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>>>         Dim IDtag As ID3v1_TAG
>>>>>>>>>         Dim hfile As File
>>>>>>>>>
>>>>>>>>>         hfile = Open File For Read
>>>>>>>>>
>>>>>>>>>             '
>>>>>>>>>             'read the tag
>>>>>>>>>             ' seek to end of less tag size
>>>>>>>>>
>>>>>>>>>             Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>
>>>>>>>>> here i get IDtag is NULL
>>>>>>>>>
>>>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>>>
>>>>>>>>> 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 <[hidden email]>
>>>>>>>>>> To: [hidden email]
>>>>>>>>>> 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
>>>>>>>>>>> [hidden email]
>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>
>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>> ------------------
>>>>>>>>>> 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
>>>>>>>>>> [hidden email]
>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>
>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>
>>>>>>>>> ------------------
>>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>>> ------------------
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>>>
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>>
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>>
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>>
>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
> ------------------------------------------------------------
> ------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Shane-2
with the code i was trying to adapt you can't

i was getting strange values eg.

a struct size of 208 when it was meant to be 128 and for some strange
reason get end of file

when seeking to eof less header even if i backed up more than the 208 bytes

i can see that tony didn't right it i should of said did he convert it
to gambas ?

i think this should be in the farm ?




On 20/07/17 21:04, Gianluigi wrote:

> 2017-07-20 12:09 GMT+02:00 Shane <[hidden email]>:
>
>> yep can't use structs have to do like tony's code works perfect thanks
>> again tony
>>
> mmmmh are you sure?
>
>
>> p.s is this your code ?
>>
> No, but you can easily see who wrote it :)
>
>
>>
>>
>> On 20/07/17 19:56, Gianluigi wrote:
>>
>>> Right ... and a look here too [0]
>>>
>>> Ciao :)
>>> Gianluigi
>>>
>>> [0] http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#msg41793
>>>
>>> 2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:
>>>
>>> thanks tony sounds like just what i needed i will take a look
>>>> cheers
>>>>
>>>>
>>>>
>>>> On 19/07/17 22:34, Tony Morehen wrote:
>>>>
>>>> I've attached an archive containing the code I use to read v1 and v2 MP3
>>>>> tags and other MP3 info including bitrates (fixed and VBR), sampling
>>>>> rates
>>>>> and number of channels.  v1 tags are pretty staightforward to read if
>>>>> you
>>>>> don't try to read the structure directly, but by each element of the
>>>>> structure at a time.  Some tips:
>>>>>
>>>>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can be
>>>>> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
>>>>> Integer.  Gambas can handle little endian/big endian issues.
>>>>>
>>>>> 2) Fixed length strings must be handled in a two stage process. First,
>>>>> the required string length number of bytes is read into a byte array.
>>>>> This
>>>>> byte array is then converted to a string. Sample code:
>>>>>
>>>>>     Dim Bytes As New Byte[StringLength]
>>>>>     Bytes.Read(Stream)
>>>>>     FixedString = Bytes.ToString()
>>>>>
>>>>> Note: Bytes.ToString stops the string conversion at the first null or at
>>>>> the end of the array.  Therfore, you don't have to worry about
>>>>> null-terminated strings.
>>>>>
>>>>> v2 tags are more complicated, particularly since the tags can be ascii,
>>>>> either kind of utf16, or utf8 encoding.  The code I sent has been tested
>>>>> with over 10,000 mp3 files has seems to have no issues.
>>>>>
>>>>>
>>>>> On 2017-07-19 12:33 AM, Shane wrote:
>>>>>
>>>>> thank you Gian i did take a rest and read but alas it did not help
>>>>>> as far as i see it he is saying don't use binary file for fixed length
>>>>>> strings
>>>>>>
>>>>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 18/07/17 19:22, Gianluigi wrote:
>>>>>>
>>>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>>>>> recommend
>>>>>>> me in the discussion [0] I told you here [1]?
>>>>>>>
>>>>>>> [0]
>>>>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>>>>> xed-length-string-td50880.html
>>>>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>>>>
>>>>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>>>>
>>>>>>> I am very confused from the docs
>>>>>>>
>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>>>>
>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>>>>
>>>>>>>> so wouldn't it be_
>>>>>>>> _
>>>>>>>>
>>>>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>>>>
>>>>>>>> with doesn't work by the way
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>>>>
>>>>>>>> I think
>>>>>>>>
>>>>>>>>>             Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>> should be
>>>>>>>>>             Read #hfile, IDtag as ID3v1_TAG
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ---------- Original Message -----------
>>>>>>>>> From: Shane <[hidden email]>
>>>>>>>>> To: [hidden email]
>>>>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>>>>
>>>>>>>>> i don't know what i am doing wrong
>>>>>>>>>
>>>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>>>>           Tag[3] As String               'always TAG
>>>>>>>>>>           Title[30] As String             'title, 30 characters
>>>>>>>>>>           Artist[30] As String           'artist, 30 characters
>>>>>>>>>>           Album[30] As String           'album, 30 characters
>>>>>>>>>>           Year[4] As String              'year, 4 characters
>>>>>>>>>>           Comment[30] As String          'comment, 30 characters (or
>>>>>>>>>> 28 if
>>>>>>>>>> track# included)
>>>>>>>>>>           Genre As Byte                   'genre, 255 for none
>>>>>>>>>> defined
>>>>>>>>>> End Struct
>>>>>>>>>>
>>>>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>>>>          Dim IDtag As ID3v1_TAG
>>>>>>>>>>          Dim hfile As File
>>>>>>>>>>
>>>>>>>>>>          hfile = Open File For Read
>>>>>>>>>>
>>>>>>>>>>              '
>>>>>>>>>>              'read the tag
>>>>>>>>>>              ' seek to end of less tag size
>>>>>>>>>>
>>>>>>>>>>              Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>>
>>>>>>>>>> here i get IDtag is NULL
>>>>>>>>>>
>>>>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>>>>
>>>>>>>>>> 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 <[hidden email]>
>>>>>>>>>>> To: [hidden email]
>>>>>>>>>>> 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
>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>
>>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>>
>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>> ------------------
>>>>>>>>>>> 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
>>>>>>>>>>> [hidden email]
>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>
>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>
>>>>>>>>>> ------------------
>>>>>>>>>> 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
>>>>>>>>>> [hidden email]
>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>
>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>>> ------------------
>>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>
>>>>>>>> ------------------
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>>> ------------------
>>>>>>>>
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>>
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user


------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Tony Morehen
It is my code.  It started off life as part of a cd ripper program I
wrote in 2010 in vb6.  It was inspired by code provided by Steve McMahon
([hidden email]) under an Apache style licence.  The code has
since been heavily rewritten, translated to vb.net and finally
translated to gambas.


On 2017-07-20 07:16 AM, Shane wrote:

> with the code i was trying to adapt you can't
>
> i was getting strange values eg.
>
> a struct size of 208 when it was meant to be 128 and for some strange
> reason get end of file
>
> when seeking to eof less header even if i backed up more than the 208
> bytes
>
> i can see that tony didn't right it i should of said did he convert it
> to gambas ?
>
> i think this should be in the farm ?
>
>
>
>
> On 20/07/17 21:04, Gianluigi wrote:
>> 2017-07-20 12:09 GMT+02:00 Shane <[hidden email]>:
>>
>>> yep can't use structs have to do like tony's code works perfect thanks
>>> again tony
>>>
>> mmmmh are you sure?
>>
>>
>>> p.s is this your code ?
>>>
>> No, but you can easily see who wrote it :)
>>
>>
>>>
>>>
>>> On 20/07/17 19:56, Gianluigi wrote:
>>>
>>>> Right ... and a look here too [0]
>>>>
>>>> Ciao :)
>>>> Gianluigi
>>>>
>>>> [0]
>>>> http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#msg41793
>>>>
>>>> 2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:
>>>>
>>>> thanks tony sounds like just what i needed i will take a look
>>>>> cheers
>>>>>
>>>>>
>>>>>
>>>>> On 19/07/17 22:34, Tony Morehen wrote:
>>>>>
>>>>> I've attached an archive containing the code I use to read v1 and
>>>>> v2 MP3
>>>>>> tags and other MP3 info including bitrates (fixed and VBR), sampling
>>>>>> rates
>>>>>> and number of channels.  v1 tags are pretty staightforward to
>>>>>> read if
>>>>>> you
>>>>>> don't try to read the structure directly, but by each element of the
>>>>>> structure at a time.  Some tips:
>>>>>>
>>>>>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs)
>>>>>> can be
>>>>>> read directly from the stream. ie  (4 byte Integer) = Read
>>>>>> #Stream As
>>>>>> Integer.  Gambas can handle little endian/big endian issues.
>>>>>>
>>>>>> 2) Fixed length strings must be handled in a two stage process.
>>>>>> First,
>>>>>> the required string length number of bytes is read into a byte
>>>>>> array.
>>>>>> This
>>>>>> byte array is then converted to a string. Sample code:
>>>>>>
>>>>>>     Dim Bytes As New Byte[StringLength]
>>>>>>     Bytes.Read(Stream)
>>>>>>     FixedString = Bytes.ToString()
>>>>>>
>>>>>> Note: Bytes.ToString stops the string conversion at the first
>>>>>> null or at
>>>>>> the end of the array.  Therfore, you don't have to worry about
>>>>>> null-terminated strings.
>>>>>>
>>>>>> v2 tags are more complicated, particularly since the tags can be
>>>>>> ascii,
>>>>>> either kind of utf16, or utf8 encoding.  The code I sent has been
>>>>>> tested
>>>>>> with over 10,000 mp3 files has seems to have no issues.
>>>>>>
>>>>>>
>>>>>> On 2017-07-19 12:33 AM, Shane wrote:
>>>>>>
>>>>>> thank you Gian i did take a rest and read but alas it did not help
>>>>>>> as far as i see it he is saying don't use binary file for fixed
>>>>>>> length
>>>>>>> strings
>>>>>>>
>>>>>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 18/07/17 19:22, Gianluigi wrote:
>>>>>>>
>>>>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>>>>>> recommend
>>>>>>>> me in the discussion [0] I told you here [1]?
>>>>>>>>
>>>>>>>> [0]
>>>>>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>>>>>> xed-length-string-td50880.html
>>>>>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>>>>>
>>>>>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>>>>>
>>>>>>>> I am very confused from the docs
>>>>>>>>
>>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>>>>>
>>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>>>>>
>>>>>>>>> so wouldn't it be_
>>>>>>>>> _
>>>>>>>>>
>>>>>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>>>>>
>>>>>>>>> with doesn't work by the way
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>>>>>
>>>>>>>>> I think
>>>>>>>>>
>>>>>>>>>>             Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>> should be
>>>>>>>>>>             Read #hfile, IDtag as ID3v1_TAG
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ---------- Original Message -----------
>>>>>>>>>> From: Shane <[hidden email]>
>>>>>>>>>> To: [hidden email]
>>>>>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>>>>>
>>>>>>>>>> i don't know what i am doing wrong
>>>>>>>>>>
>>>>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>>>>>           Tag[3] As String               'always TAG
>>>>>>>>>>>           Title[30] As String 'title, 30 characters
>>>>>>>>>>>           Artist[30] As String 'artist, 30 characters
>>>>>>>>>>>           Album[30] As String 'album, 30 characters
>>>>>>>>>>>           Year[4] As String 'year, 4 characters
>>>>>>>>>>>           Comment[30] As String 'comment, 30 characters (or
>>>>>>>>>>> 28 if
>>>>>>>>>>> track# included)
>>>>>>>>>>>           Genre As Byte 'genre, 255 for none
>>>>>>>>>>> defined
>>>>>>>>>>> End Struct
>>>>>>>>>>>
>>>>>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>>>>>          Dim IDtag As ID3v1_TAG
>>>>>>>>>>>          Dim hfile As File
>>>>>>>>>>>
>>>>>>>>>>>          hfile = Open File For Read
>>>>>>>>>>>
>>>>>>>>>>>              '
>>>>>>>>>>>              'read the tag
>>>>>>>>>>>              ' seek to end of less tag size
>>>>>>>>>>>
>>>>>>>>>>>              Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>>>
>>>>>>>>>>> here i get IDtag is NULL
>>>>>>>>>>>
>>>>>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>>>>>
>>>>>>>>>>> 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 <[hidden email]>
>>>>>>>>>>>> To: [hidden email]
>>>>>>>>>>>> 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
>>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>>
>>>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>>>
>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>> ------------------
>>>>>>>>>>>> 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
>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>
>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>>
>>>>>>>>>>> ------------------
>>>>>>>>>>> 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
>>>>>>>>>>> [hidden email]
>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>
>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>
>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>> ------------------
>>>>>>>>>> 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
>>>>>>>>>> [hidden email]
>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>
>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>
>>>>>>>>> ------------------
>>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>>> ------------------
>>>>>>>>>
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>>
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>> ------------------------------------------------------------------------------
>>
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
> ------------------------------------------------------------------------------
>
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Gianluigi
Hi Tony,
Sorry if i answered  instead of you, but I did not understand who the
question was for :-(

Regards
Gianluigi

2017-07-20 15:35 GMT+02:00 Tony Morehen <[hidden email]>:

> It is my code.  It started off life as part of a cd ripper program I wrote
> in 2010 in vb6.  It was inspired by code provided by Steve McMahon (
> [hidden email]) under an Apache style licence.  The code has
> since been heavily rewritten, translated to vb.net and finally translated
> to gambas.
>
>
> On 2017-07-20 07:16 AM, Shane wrote:
>
>> with the code i was trying to adapt you can't
>>
>> i was getting strange values eg.
>>
>> a struct size of 208 when it was meant to be 128 and for some strange
>> reason get end of file
>>
>> when seeking to eof less header even if i backed up more than the 208
>> bytes
>>
>> i can see that tony didn't right it i should of said did he convert it to
>> gambas ?
>>
>> i think this should be in the farm ?
>>
>>
>>
>>
>> On 20/07/17 21:04, Gianluigi wrote:
>>
>>> 2017-07-20 12:09 GMT+02:00 Shane <[hidden email]>:
>>>
>>> yep can't use structs have to do like tony's code works perfect thanks
>>>> again tony
>>>>
>>>> mmmmh are you sure?
>>>
>>>
>>> p.s is this your code ?
>>>>
>>>> No, but you can easily see who wrote it :)
>>>
>>>
>>>
>>>>
>>>> On 20/07/17 19:56, Gianluigi wrote:
>>>>
>>>> Right ... and a look here too [0]
>>>>>
>>>>> Ciao :)
>>>>> Gianluigi
>>>>>
>>>>> [0] http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#m
>>>>> sg41793
>>>>>
>>>>> 2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:
>>>>>
>>>>> thanks tony sounds like just what i needed i will take a look
>>>>>
>>>>>> cheers
>>>>>>
>>>>>>
>>>>>>
>>>>>> On 19/07/17 22:34, Tony Morehen wrote:
>>>>>>
>>>>>> I've attached an archive containing the code I use to read v1 and v2
>>>>>> MP3
>>>>>>
>>>>>>> tags and other MP3 info including bitrates (fixed and VBR), sampling
>>>>>>> rates
>>>>>>> and number of channels.  v1 tags are pretty staightforward to read if
>>>>>>> you
>>>>>>> don't try to read the structure directly, but by each element of the
>>>>>>> structure at a time.  Some tips:
>>>>>>>
>>>>>>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can
>>>>>>> be
>>>>>>> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
>>>>>>> Integer.  Gambas can handle little endian/big endian issues.
>>>>>>>
>>>>>>> 2) Fixed length strings must be handled in a two stage process.
>>>>>>> First,
>>>>>>> the required string length number of bytes is read into a byte array.
>>>>>>> This
>>>>>>> byte array is then converted to a string. Sample code:
>>>>>>>
>>>>>>>     Dim Bytes As New Byte[StringLength]
>>>>>>>     Bytes.Read(Stream)
>>>>>>>     FixedString = Bytes.ToString()
>>>>>>>
>>>>>>> Note: Bytes.ToString stops the string conversion at the first null
>>>>>>> or at
>>>>>>> the end of the array.  Therfore, you don't have to worry about
>>>>>>> null-terminated strings.
>>>>>>>
>>>>>>> v2 tags are more complicated, particularly since the tags can be
>>>>>>> ascii,
>>>>>>> either kind of utf16, or utf8 encoding.  The code I sent has been
>>>>>>> tested
>>>>>>> with over 10,000 mp3 files has seems to have no issues.
>>>>>>>
>>>>>>>
>>>>>>> On 2017-07-19 12:33 AM, Shane wrote:
>>>>>>>
>>>>>>> thank you Gian i did take a rest and read but alas it did not help
>>>>>>>
>>>>>>>> as far as i see it he is saying don't use binary file for fixed
>>>>>>>> length
>>>>>>>> strings
>>>>>>>>
>>>>>>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 18/07/17 19:22, Gianluigi wrote:
>>>>>>>>
>>>>>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>>>>>>
>>>>>>>>> recommend
>>>>>>>>> me in the discussion [0] I told you here [1]?
>>>>>>>>>
>>>>>>>>> [0]
>>>>>>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>>>>>>> xed-length-string-td50880.html
>>>>>>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>>>>>>
>>>>>>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>>>>>>
>>>>>>>>> I am very confused from the docs
>>>>>>>>>
>>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>>>>>>
>>>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>>>>>>
>>>>>>>>>> so wouldn't it be_
>>>>>>>>>> _
>>>>>>>>>>
>>>>>>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>>>>>>
>>>>>>>>>> with doesn't work by the way
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>>>>>>
>>>>>>>>>> I think
>>>>>>>>>>
>>>>>>>>>>             Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>>> should be
>>>>>>>>>>>             Read #hfile, IDtag as ID3v1_TAG
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> ---------- Original Message -----------
>>>>>>>>>>> From: Shane <[hidden email]>
>>>>>>>>>>> To: [hidden email]
>>>>>>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>>>>>>
>>>>>>>>>>> i don't know what i am doing wrong
>>>>>>>>>>>
>>>>>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>>>>>
>>>>>>>>>>>>           Tag[3] As String               'always TAG
>>>>>>>>>>>>           Title[30] As String 'title, 30 characters
>>>>>>>>>>>>           Artist[30] As String 'artist, 30 characters
>>>>>>>>>>>>           Album[30] As String 'album, 30 characters
>>>>>>>>>>>>           Year[4] As String 'year, 4 characters
>>>>>>>>>>>>           Comment[30] As String 'comment, 30 characters (or
>>>>>>>>>>>> 28 if
>>>>>>>>>>>> track# included)
>>>>>>>>>>>>           Genre As Byte 'genre, 255 for none
>>>>>>>>>>>> defined
>>>>>>>>>>>> End Struct
>>>>>>>>>>>>
>>>>>>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>>>>>>          Dim IDtag As ID3v1_TAG
>>>>>>>>>>>>          Dim hfile As File
>>>>>>>>>>>>
>>>>>>>>>>>>          hfile = Open File For Read
>>>>>>>>>>>>
>>>>>>>>>>>>              '
>>>>>>>>>>>>              'read the tag
>>>>>>>>>>>>              ' seek to end of less tag size
>>>>>>>>>>>>
>>>>>>>>>>>>              Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>>>>
>>>>>>>>>>>> here i get IDtag is NULL
>>>>>>>>>>>>
>>>>>>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>>>>>>
>>>>>>>>>>>> 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 <[hidden email]>
>>>>>>>>>>>>> To: [hidden email]
>>>>>>>>>>>>> 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
>>>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>>> ------------------
>>>>>>>>>>>>> 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
>>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>>
>>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>>>
>>>>>>>>>>>>> ------------------
>>>>>>>>>>>> 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
>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>
>>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>>
>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>> ------------------
>>>>>>>>>>> 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
>>>>>>>>>>> [hidden email]
>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>
>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>
>>>>>>>>>>> ------------------
>>>>>>>>>> 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
>>>>>>>>>> [hidden email]
>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>
>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>> ------------------
>>>>>>>>>>
>>>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>> ------------------
>>>>>>>>
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>>
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>> ------------------------------------------------------------
>>>>>>
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>>
>>>> ------------------------------------------------------------
>>>> ------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>> ------------------------------------------------------------------------------
>>>
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>
>
>
> ------------------------------------------------------------
> ------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Tony Morehen
I've uploaded the class with a short command line demo to the software farm.


On 2017-07-20 12:22 PM, Gianluigi wrote:

> Hi Tony,
> Sorry if i answered  instead of you, but I did not understand who the
> question was for :-(
>
> Regards
> Gianluigi
>
> 2017-07-20 15:35 GMT+02:00 Tony Morehen <[hidden email]>:
>
>> It is my code.  It started off life as part of a cd ripper program I wrote
>> in 2010 in vb6.  It was inspired by code provided by Steve McMahon (
>> [hidden email]) under an Apache style licence.  The code has
>> since been heavily rewritten, translated to vb.net and finally translated
>> to gambas.
>>
>>
>> On 2017-07-20 07:16 AM, Shane wrote:
>>
>>> with the code i was trying to adapt you can't
>>>
>>> i was getting strange values eg.
>>>
>>> a struct size of 208 when it was meant to be 128 and for some strange
>>> reason get end of file
>>>
>>> when seeking to eof less header even if i backed up more than the 208
>>> bytes
>>>
>>> i can see that tony didn't right it i should of said did he convert it to
>>> gambas ?
>>>
>>> i think this should be in the farm ?
>>>
>>>
>>>
>>>
>>> On 20/07/17 21:04, Gianluigi wrote:
>>>
>>>> 2017-07-20 12:09 GMT+02:00 Shane <[hidden email]>:
>>>>
>>>> yep can't use structs have to do like tony's code works perfect thanks
>>>>> again tony
>>>>>
>>>>> mmmmh are you sure?
>>>>
>>>> p.s is this your code ?
>>>>> No, but you can easily see who wrote it :)
>>>>
>>>>
>>>>> On 20/07/17 19:56, Gianluigi wrote:
>>>>>
>>>>> Right ... and a look here too [0]
>>>>>> Ciao :)
>>>>>> Gianluigi
>>>>>>
>>>>>> [0] http://www.gambas-it.org/smf/index.php?topic=5794.msg41793#m
>>>>>> sg41793
>>>>>>
>>>>>> 2017-07-20 3:15 GMT+02:00 Shane <[hidden email]>:
>>>>>>
>>>>>> thanks tony sounds like just what i needed i will take a look
>>>>>>
>>>>>>> cheers
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 19/07/17 22:34, Tony Morehen wrote:
>>>>>>>
>>>>>>> I've attached an archive containing the code I use to read v1 and v2
>>>>>>> MP3
>>>>>>>
>>>>>>>> tags and other MP3 info including bitrates (fixed and VBR), sampling
>>>>>>>> rates
>>>>>>>> and number of channels.  v1 tags are pretty staightforward to read if
>>>>>>>> you
>>>>>>>> don't try to read the structure directly, but by each element of the
>>>>>>>> structure at a time.  Some tips:
>>>>>>>>
>>>>>>>> 1) Numeric elements (bytes, bytearrays, shorts, integers, longs) can
>>>>>>>> be
>>>>>>>> read directly from the stream. ie  (4 byte Integer) = Read #Stream As
>>>>>>>> Integer.  Gambas can handle little endian/big endian issues.
>>>>>>>>
>>>>>>>> 2) Fixed length strings must be handled in a two stage process.
>>>>>>>> First,
>>>>>>>> the required string length number of bytes is read into a byte array.
>>>>>>>> This
>>>>>>>> byte array is then converted to a string. Sample code:
>>>>>>>>
>>>>>>>>      Dim Bytes As New Byte[StringLength]
>>>>>>>>      Bytes.Read(Stream)
>>>>>>>>      FixedString = Bytes.ToString()
>>>>>>>>
>>>>>>>> Note: Bytes.ToString stops the string conversion at the first null
>>>>>>>> or at
>>>>>>>> the end of the array.  Therfore, you don't have to worry about
>>>>>>>> null-terminated strings.
>>>>>>>>
>>>>>>>> v2 tags are more complicated, particularly since the tags can be
>>>>>>>> ascii,
>>>>>>>> either kind of utf16, or utf8 encoding.  The code I sent has been
>>>>>>>> tested
>>>>>>>> with over 10,000 mp3 files has seems to have no issues.
>>>>>>>>
>>>>>>>>
>>>>>>>> On 2017-07-19 12:33 AM, Shane wrote:
>>>>>>>>
>>>>>>>> thank you Gian i did take a rest and read but alas it did not help
>>>>>>>>
>>>>>>>>> as far as i see it he is saying don't use binary file for fixed
>>>>>>>>> length
>>>>>>>>> strings
>>>>>>>>>
>>>>>>>>> but as this is an mp3 file tag witch i have no control i am doomed
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On 18/07/17 19:22, Gianluigi wrote:
>>>>>>>>>
>>>>>>>>> Why do not you take a moment of rest and read what Tobias Boege
>>>>>>>>>
>>>>>>>>>> recommend
>>>>>>>>>> me in the discussion [0] I told you here [1]?
>>>>>>>>>>
>>>>>>>>>> [0]
>>>>>>>>>> http://gambas.8142.n7.nabble.com/Random-access-files-with-fi
>>>>>>>>>> xed-length-string-td50880.html
>>>>>>>>>> [1] http://gambas.8142.n7.nabble.com/vb-code-td59764.html
>>>>>>>>>>
>>>>>>>>>> 2017-07-18 9:04 GMT+02:00 Shane <[hidden email]>:
>>>>>>>>>>
>>>>>>>>>> I am very confused from the docs
>>>>>>>>>>
>>>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ ] *AS* _Datatype_
>>>>>>>>>>> _Variable_ *= READ* [ *#* _Stream_ *,* ] _Length_
>>>>>>>>>>>
>>>>>>>>>>> so wouldn't it be_
>>>>>>>>>>> _
>>>>>>>>>>>
>>>>>>>>>>> IDtag = read #hfile  as ID3v1_TAG  ?
>>>>>>>>>>>
>>>>>>>>>>> with doesn't work by the way
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On 18/07/17 12:44, [hidden email] wrote:
>>>>>>>>>>>
>>>>>>>>>>> I think
>>>>>>>>>>>
>>>>>>>>>>>              Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>>>> should be
>>>>>>>>>>>>              Read #hfile, IDtag as ID3v1_TAG
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> Open WebMail Project (http://openwebmail.org)
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> ---------- Original Message -----------
>>>>>>>>>>>> From: Shane <[hidden email]>
>>>>>>>>>>>> To: [hidden email]
>>>>>>>>>>>> Sent: Tue, 18 Jul 2017 10:50:43 +1000
>>>>>>>>>>>> Subject: Re: [Gambas-user] reading files
>>>>>>>>>>>>
>>>>>>>>>>>> i don't know what i am doing wrong
>>>>>>>>>>>>
>>>>>>>>>>>> Public Struct ID3v1_TAG '(128 bytes)
>>>>>>>>>>>>
>>>>>>>>>>>>>            Tag[3] As String               'always TAG
>>>>>>>>>>>>>            Title[30] As String 'title, 30 characters
>>>>>>>>>>>>>            Artist[30] As String 'artist, 30 characters
>>>>>>>>>>>>>            Album[30] As String 'album, 30 characters
>>>>>>>>>>>>>            Year[4] As String 'year, 4 characters
>>>>>>>>>>>>>            Comment[30] As String 'comment, 30 characters (or
>>>>>>>>>>>>> 28 if
>>>>>>>>>>>>> track# included)
>>>>>>>>>>>>>            Genre As Byte 'genre, 255 for none
>>>>>>>>>>>>> defined
>>>>>>>>>>>>> End Struct
>>>>>>>>>>>>>
>>>>>>>>>>>>> Private Sub GetID3v1(File As String)
>>>>>>>>>>>>>           Dim IDtag As ID3v1_TAG
>>>>>>>>>>>>>           Dim hfile As File
>>>>>>>>>>>>>
>>>>>>>>>>>>>           hfile = Open File For Read
>>>>>>>>>>>>>
>>>>>>>>>>>>>               '
>>>>>>>>>>>>>               'read the tag
>>>>>>>>>>>>>               ' seek to end of less tag size
>>>>>>>>>>>>>
>>>>>>>>>>>>>               Read #hfile, IDtag, ID3v1_TAG
>>>>>>>>>>>>>
>>>>>>>>>>>>> here i get IDtag is NULL
>>>>>>>>>>>>>
>>>>>>>>>>>>> On 18/07/17 05:05, [hidden email] wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>> 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 <[hidden email]>
>>>>>>>>>>>>>> To: [hidden email]
>>>>>>>>>>>>>> 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
>>>>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>>>> ------------------
>>>>>>>>>>>>>> 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
>>>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> ------------------
>>>>>>>>>>>>> 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
>>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>>
>>>>>>>>>>>>> ------- End of Original Message -------
>>>>>>>>>>>>>
>>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>> ------------------
>>>>>>>>>>>> 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
>>>>>>>>>>>> [hidden email]
>>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>>
>>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>>>
>>>>>>>>>>>> ------------------
>>>>>>>>>>> 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
>>>>>>>>>>> [hidden email]
>>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>>
>>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>>>> ------------------
>>>>>>>>>>>
>>>>>>>>>>> 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
>>>>>>>>>> [hidden email]
>>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> ------------------------------------------------------------
>>>>>>>>> ------------------
>>>>>>>>>
>>>>>>>>> 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
>>>>>>>>> [hidden email]
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> ------------------------------------------------------------
>>>>>>>> ------------------
>>>>>>>> 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
>>>>>>>> [hidden email]
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>>
>>>>>>>> ------------------------------------------------------------
>>>>>>>>
>>>>>>> ------------------
>>>>>>> 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
>>>>>>> [hidden email]
>>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>>
>>>>>>> ------------------------------------------------------------
>>>>>>>
>>>>>> ------------------
>>>>>> 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
>>>>>> [hidden email]
>>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>>
>>>>>>
>>>>> ------------------------------------------------------------
>>>>> ------------------
>>>>> 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
>>>>> [hidden email]
>>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>>
>>>>> ------------------------------------------------------------------------------
>>>> 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
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>>
>>>
>>> ------------------------------------------------------------------------------
>>>
>>> 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
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>>
>>
>>
>> ------------------------------------------------------------
>> ------------------
>> 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
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
> ------------------------------------------------------------------------------
> 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
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gambas-user



------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: reading files

Hans Lehmann
Am 20.07.2017 um 20:27 schrieb Tony Morehen:
> I've uploaded the class with a short command line demo to the software
> farm.

Hello Tony,

under which heading can I find the class in the software farm?

Honsek
------------------------------------------------------------------------------
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
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gambas-user
12
Loading...