Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Leggere file binario scritto in vb6
Forum - C# / VB.NET - Leggere file binario scritto in vb6

Avatar
dartraf (Normal User)
Pro


Messaggi: 71
Iscritto: 15/12/2005

Segnala al moderatore
Postato alle 19:55
Giovedė, 04/03/2010
Ciao
ho scritto un file binario in vb6 con la seguente struttura

Codice sorgente - presumibilmente VB.NET

  1. Private Type structFile
  2.     data As Date
  3.     num As Integer
  4. 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?

PM Quote
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 20:11
Giovedė, 04/03/2010
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ė:
Codice sorgente - presumibilmente VB.NET

  1. Dim File As New IO.FileStream("file", IO.FileMode.Open)
  2. Dim Reader As New IO.BinaryReader(File)
  3.  
  4. Do While Reader.BaseStream.Position < Reader.BaseStream.Length - 1
  5.    Dim I As Int32
  6.    Dim D As Date
  7.    I = Reader.ReadInt32()
  8.    D = Date.FromBinary(Reader.ReadInt64())
  9. Loop
  10.  
  11. Reader.Close()
  12. File.Close()


PM Quote