Oppure

Loading
04/03/10 18:55
dartraf
Ciao
ho scritto un file binario in vb6 con la seguente struttura

Private Type structFile
    data As Date
    num As Integer
End Type


volevo sapere come posso fare a leggere il dati (che sono tanti record di quel tipo definito da me) con vb net. Non esistono i comandi get?
aaa
04/03/10 19:11
Il Totem
BinaryReader ti consente di leggere dati scritti in binario. La funzione ReadInt32 legge un integer (anche se è probabile che in vb6 integer sia a 16 bit, quindi ReadInt16). Non esiste un metodo per leggere date purtroppo. Tuttavia i valori Date vengono salvati come interi a 64 bit, quindi puoi ottenere il dato corrispondente con Date.FromBinary.
Ad esempio così:
Dim File As New IO.FileStream("file", IO.FileMode.Open)
Dim Reader As New IO.BinaryReader(File)

Do While Reader.BaseStream.Position < Reader.BaseStream.Length - 1
   Dim I As Int32
   Dim D As Date
   I = Reader.ReadInt32()
   D = Date.FromBinary(Reader.ReadInt64())
Loop

Reader.Close()
File.Close()
aaa