[RESOLVED] [2005] This code in vb 2005
Code:
If response = vbYes Then
Open "adress.txt" For Binary As #1 Len = Len(Test300Record)
Open "adress.tmp" For Binary As #2 Len = Len(Test500Record)
Get #1, , Test300Record
Do While Not EOF(1) ' Loop until end of file.
filpekare = LOF(2)
Test500Record.Name = Test300Record.Name
Test500Record.ID = filpekare
Put #2, filpekare + 1, Test500Record
Get #1, , Test300Record
Loop
What is this code in visual basic 2005.
Re: [2005] This code in vb 2005
You need to post complete code including all declarations (variables, types, arrays, etc).
Re: [2005] This code in vb 2005
Anyway, you can serialize your structure and also use BinaryFormatter to write the entire structure (single record or array) directly to a binary file:
Code:
Option Explicit On
Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> _
Structure myStructure
Dim myID As Long
Dim myName As String
End Structure
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myDataOut(2) As myStructure
Dim i As Integer
Dim fs As FileStream = File.Open("c:\my_structure.dat", FileMode.OpenOrCreate)
Dim bf As New BinaryFormatter
'set up structure
For i = 1 To 3
myDataOut(i - 1).myID = i
myDataOut(i - 1).myName = "Rhino" & i
Next i
'write data to a file
bf.Serialize(fs, myDataOut)
fs.Close()
'read data from a file
fs = File.Open("c:\my_structure.dat", FileMode.Open)
Dim myDataIn() As myStructure = DirectCast(bf.Deserialize(fs), myStructure())
fs.Close()
'test data
For i = 0 To myDataIn.Length - 1
Debug.Print(myDataIn(i).myID & " " & myDataIn(i).myName)
Next i
End Sub
End Class
You can follow the same principals to convert your code.