VERSION 5.00 Begin VB.Form frmDisplayBooks Caption = "Display Books" ClientHeight = 1932 ClientLeft = 1548 ClientTop = 3036 ClientWidth = 6048 LinkTopic = "Form1" ScaleHeight = 1932 ScaleWidth = 6048 Begin VB.CommandButton cmdSelectBook Caption = "Select Book" Height = 372 Left = 4440 TabIndex = 6 Top = 720 Width = 1452 End Begin VB.CommandButton cmdDone Caption = "Done" Height = 372 Left = 4440 TabIndex = 5 Top = 1320 Width = 1452 End Begin VB.CommandButton cmdViewNextBook Caption = "View Next Book" Height = 372 Left = 4440 TabIndex = 4 Top = 240 Width = 1452 End Begin VB.TextBox txtAuthor Height = 288 Left = 1080 TabIndex = 3 Top = 720 Width = 2292 End Begin VB.TextBox txtTitle Height = 288 Left = 840 TabIndex = 1 Top = 240 Width = 2892 End Begin VB.Line Line1 BorderWidth = 2 X1 = 4440 X2 = 5880 Y1 = 1200 Y2 = 1200 End Begin VB.Label lblAuthor Caption = "Author:" Height = 252 Left = 240 TabIndex = 2 Top = 720 Width = 732 End Begin VB.Label lblTitle Caption = "Title:" Height = 252 Left = 240 TabIndex = 0 Top = 240 Width = 492 End End Attribute VB_Name = "frmDisplayBooks" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Type BookRecord strTitle As String * 30 strAuthor As String * 30 End Type Private Sub Form_Load() Call InitializeForm End Sub '**************************************************** ' Clears form ' ' post: Text boxes on form are empty '**************************************************** Sub InitializeForm() txtTitle.Text = "" txtAuthor.Text = "" End Sub Private Sub cmdSelectBook_Click() frmGiftOrderForm.lstBooksOrdered.AddItem txtTitle.Text End Sub Private Sub cmdViewNextBook_Click() Dim udtNewBook As BookRecord Dim intBookFile As Integer, lngRecLength As Long Dim lngTotalRecords As Long Static lngRecNum As Long 'Open file intBookFile = FreeFile lngRecLength = LenB(udtNewBook) Open "Giftbooks.dat" For Random As #intBookFile _ Len = lngRecLength 'Determine number of records lngTotalRecords = NumRecords(intBookFile, lngRecLength) 'View record if valid If lngRecNum < lngTotalRecords Then lngRecNum = lngRecNum + 1 Else lngRecNum = 1 End If Get #intBookFile, lngRecNum, udtNewBook txtTitle.Text = udtNewBook.strTitle txtAuthor.Text = udtNewBook.strAuthor 'Close file Close #intBookFile End Sub '************************************************************* ' Returns the number of records in the file with intFileNum ' file number containing records of length lngRecLength ' ' pre: intFileNum is open ' post: Number of records in intFileNum returned '************************************************************* Function NumRecords(ByVal intFileNum As Integer, _ ByVal lngRecLength As Long) As Integer If LOF(intFileNum) Mod lngRecLength = 0 Then NumRecords = (LOF(intFileNum) \ lngRecLength) Else NumRecords = (LOF(intFileNum) \ lngRecLength) + 1 End If End Function Private Sub cmdDone_Click() Unload Me End Sub