Sub writeprod(pezziin As ULong, allarmiin As ULong,prodottox As Int )
Dim raf As RandomAccessFile
Dim buffer(18) As Byte
raf.Initialize(buffer,True)
Dim offset As Int = prodottox * 10 + 14
Dim nomeprod() As Byte=leggiparam("macch",bc.StringToBytes(JoinStrings(Array As String( "P", NumberFormat( offset + 10,1,0)))))
Main.sd.Position = prodottox * buffer.Length
Log("Scrive prodotto:",prodottox, " pos: ",prodottox*buffer.Length)
'fill the buffer from the file
Main.sd.Stream.ReadBytes(buffer, 0, buffer.Length)
Dim r As Record
raf.CurrentPosition = 0
'read the data from the buffer
r.pezzi = raf.ReadULong32( raf.CurrentPosition)
r.allarmi = raf.ReadDouble32(raf.CurrentPosition)
raf.CurrentPosition=0
Main.sd.Position = prodottox * buffer.Length
Log("sd.position:",Main.sd.Position)
raf.WriteULong32(r.pezzi+pezziin,raf.CurrentPosition)
raf.WriteULong32(r.allarmi+allarmiin,raf.CurrentPosition)
raf.WriteBytes(nomeprod,0,nomeprod.Length,raf.CurrentPosition)
Main.sd.Stream.WriteBytes(buffer,0,buffer.Length)
End Sub