Ik ben bezig om een applicatie geschreven in VB6 om te zetten naar VB.NET. Deels omdat het dan als plug-in te gebruiken is in een ander programma, deels om VB.NET te leren.
Ik zit momenteel vast op het gedeelte waar ik een binaire bestand moet openen en vervolgens data eruit te halen en weg te schrijven naar een ASCII-bestand.
Het binaire bestand bestaat uit een header en data (in dit geval een gridbestand). Het uitlezen van de header gaat al goed alleen het lezen van de data nog niet. In VB6 deed ik dat door de data in een array te stoppen, maar ik kan de VB.NET versie niet vinden.
Hier is de VB6 code:
Dit is de code die ik in VB.NET gebruik:
Graag advies hoe dit op te lossen.
Ik zit momenteel vast op het gedeelte waar ik een binaire bestand moet openen en vervolgens data eruit te halen en weg te schrijven naar een ASCII-bestand.
Het binaire bestand bestaat uit een header en data (in dit geval een gridbestand). Het uitlezen van de header gaat al goed alleen het lezen van de data nog niet. In VB6 deed ik dat door de data in een array te stoppen, maar ik kan de VB.NET versie niet vinden.
Hier is de VB6 code:
Visual Basic 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| Dim nRows As Long Dim nCols As Long Dim lDataLength As Long Dim xLL As Double, yLL As Double Dim xSize As Double, ySize As Double, blankValue As Double lFileBinaryRead = FreeFile Open sTempname For Binary As #lFileBinaryRead 'Overzicht staat op: 'http://www.geospatialdesigns.com/surfer7_format.htm 'Lees de header: Get #lFileBinaryRead, 21, nRows Get #lFileBinaryRead, 25, nCols Get #lFileBinaryRead, 29, xLL Get #lFileBinaryRead, 37, yLL Get #lFileBinaryRead, 45, xSize Get #lFileBinaryRead, 53, ySize Get #lFileBinaryRead, 85, blankValue lDataLength = ((nRows * nCols) - 1) ReDim arr(lDataLength) 'Lees de data Get #lFileBinaryRead, 101, arr 'Bestand sluiten: Close #lFileBinaryRead |
Dit is de code die ik in VB.NET gebruik:
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| Dim fs As System.IO.FileStream = New System.IO.FileStream(sGridFilename, IO.FileMode.Open) Dim br As System.IO.BinaryReader = New System.IO.BinaryReader(fs) 'Overview at http://www.geospatialdesigns.com/surfer7_format.htm 'Lees de header: br.ReadInt32() 'Tag: Id for Header section: 4 bytes br.ReadInt32() 'Tag: Size of Header section: 4 bytes br.ReadInt32() 'Header Section: Version: 4 bytes br.ReadInt32() 'Tag: ID indicating a grid section: 4 bytes br.ReadInt32() 'Tag: Length in bytes of the grid section: 4 bytes Dim nRows As Integer = br.ReadInt32() 'Grid Section: nRow: 4 bytes Dim nCols As Integer = br.ReadInt32() 'Grid Section: nCol: 4 bytes Dim xLL As Double = br.ReadDouble() 'Grid Section: xLL: 8 bytes Dim yLL As Double = br.ReadDouble() 'Grid Section: yLL: 8 bytes Dim xSize As Double = br.ReadDouble() 'Grid Section: xSize: 8 bytes Dim ySize As Double = br.ReadDouble() 'Grid Section: ySize: 8 bytes br.ReadDouble() 'Grid Section: zMin: 8 bytes br.ReadDouble() 'Grid Section: zMax: 8 bytes br.ReadDouble() 'Grid Section: Rotation: 8 bytes Dim BlankValue As Double = br.ReadDouble() 'Grid Section: BlankValue: 8 bytes br.ReadInt32() 'Tag: ID indicating a data section: 4 bytes br.ReadInt32() 'Tag: Length in bytes of the data section (5 rows x 10 columns x 8 bytes per double): 4 bytes 'Read griddata: Dim DataLength As Integer = ((nRows * nCols) - 1) Dim griddata(DataLength) As Double 'Lees de data, hier kom ik niet uit: 'br.Read( 'Grid data. First value is the lower left node, and the subsequent nodes procede across the row until the end, then up to the second row, etc., until finishing at the upper right node: 8 bytes 'Close br.Close() |
Graag advies hoe dit op te lossen.