[Gambas-user] Setting at zero more byte in a file by "Byte[]"

Emil Lenngren emil.lenngren at ...626...
Mon Apr 9 00:17:15 CEST 2012


When you write
      For Each b In buff
        b = 0
      Next
you get a copy of each byte in the variable 'b', not a reference.
Instead, you can do something like this:
      For i = 0 To 3
        buff[i] = 0
      Next

/Emil

2012/4/8 Ru Vuott <vuott at ...325...>

> Hello,
>
> I'ld like to set at zero more subsequent byte (e.g. the FIRST four) in a
> file, using that code:
>
> ***
>    Public Sub Button1_Click()
>
>     Dim aFl As File
>     Dim buff As New Byte[4]
>     Dim b As Byte
>
>       aFl = Open "/tmp/my_file" For Write
>
>       For Each b In buff
>         b = 0
>       Next
>
>        Write #aFl, buff As Byte[]
>
>       aFl.Close
>
>    End
> ***
>
> But I obtain a "strange" result. In fact if I control the result of file
> by an exad. editor, I see the byte are:
>
>  41 02 04 00 00 00 00 ......
>
> I have three "strange" byte (41 02 04) end 'then' the four zero !
> If I want to set at zero five byte, those three exad. number will be: 41
> 02 05 .... It seems it memorized and wrote the array pointer instead of its
> contents (the four zero) !
>
> Isn't it ?
>
> Vuott
>
>
> ------------------------------------------------------------------------------
> For Developers, A Lot Can Happen In A Second.
> Boundary is the first to Know...and Tell You.
> Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
> http://p.sf.net/sfu/Boundary-d2dvs2
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list