Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21090

read from random access file

$
0
0
Can someone help me explain the code snippet below:
Why am I getting "1" when reading "Buks(2).Index" in Private Sub Command2_Click().
Its value should be "88".
Also, when reading "Buks(2).Saved" I am getting "False" instead of "True".

Option Explicit
Dim filenum As Integer

Private Type Book_data
Index As Integer
Title As String * 25
Author As String * 20
Saved As Boolean
End Type

Private Sub Command1_Click()

Dim Books(100) As Book_data

filenum = FreeFile
Open "D:\BOOKFILE.dat" For Random As #filenum Len = Len(Books(2))

Books(1).Index = 1
Books(1).Author = "AAA"
Books(1).Title = "BBB"
Books(1).Saved = False
Put #filenum, 1, Books(1)

Books(2).Index = 88
Books(2).Author = "CCC"
Books(2).Title = "DDD"
Books(2).Saved = True
Put #filenum, 2, Books(2)

End Sub

Private Sub Command2_Click()

Dim Buks(100) As Book_data
Get #filenum, 1, Buks(2)
MsgBox (Buks(2).Index)
End Sub

Viewing all articles
Browse latest Browse all 21090

Trending Articles