⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 Visual Basic 6 大学教程的代码
💻 FRM
字号:
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "Read from a Random-Access File"
   ClientHeight    =   2310
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4710
   LinkTopic       =   "Form1"
   ScaleHeight     =   2310
   ScaleWidth      =   4710
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdNext 
      Caption         =   "Next Record"
      Height          =   375
      Left            =   0
      TabIndex        =   5
      Top             =   1920
      Width           =   2295
   End
   Begin VB.TextBox txtAccount 
      Height          =   285
      Left            =   1320
      TabIndex        =   1
      Top             =   480
      Width           =   3375
   End
   Begin VB.TextBox txtFirstName 
      Height          =   285
      Left            =   1320
      TabIndex        =   2
      Top             =   840
      Width           =   3375
   End
   Begin VB.TextBox txtLastName 
      Height          =   285
      Left            =   1320
      TabIndex        =   3
      Top             =   1200
      Width           =   3375
   End
   Begin VB.TextBox txtBalance 
      Height          =   285
      Left            =   1320
      TabIndex        =   4
      Top             =   1560
      Width           =   3375
   End
   Begin MSComDlg.CommonDialog dlgOpen 
      Left            =   2640
      Top             =   0
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      DialogTitle     =   "Specify File to Read"
      Filter          =   "Random-access files (*.rnd) | *.rnd"
      InitDir         =   "c:\"
   End
   Begin VB.CommandButton cmdOpenFile 
      Caption         =   "Select a file"
      Height          =   375
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   4695
   End
   Begin VB.CommandButton cmdDone 
      Caption         =   "Done"
      Height          =   375
      Left            =   2400
      TabIndex        =   7
      Top             =   1920
      Width           =   2295
   End
   Begin VB.Label lblAccount 
      Alignment       =   1  'Right Justify
      Caption         =   "Account number:"
      Height          =   255
      Left            =   0
      TabIndex        =   10
      Top             =   495
      Width           =   1215
   End
   Begin VB.Label lblFirstName 
      Alignment       =   1  'Right Justify
      Caption         =   "First name:"
      Height          =   255
      Left            =   0
      TabIndex        =   9
      Top             =   855
      Width           =   1215
   End
   Begin VB.Label lblLastName 
      Alignment       =   1  'Right Justify
      Caption         =   "Last name:"
      Height          =   255
      Left            =   0
      TabIndex        =   8
      Top             =   1215
      Width           =   1215
   End
   Begin VB.Label lblBalance 
      Alignment       =   1  'Right Justify
      Caption         =   "Balance:"
      Height          =   255
      Left            =   0
      TabIndex        =   6
      Top             =   1575
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 15.6
' Reading data sequentially from a random-access file
Option Explicit

Private Type ClientRecord
   accountNumber As Integer
   lastName As String * 15
   firstName As String * 15
   balance As Currency
End Type

Dim mUdtClient As ClientRecord   ' user defined type

Private Sub Form_Load()
   cmdNext.Enabled = False
   cmdDone.Enabled = False
End Sub

Sub cmdOpenFile_Click()
   Dim recordLength As Long
   Dim filename As String
   
   ' Determine number of bytes in a ClientRecord object
   recordLength = LenB(mUdtClient)
   
   dlgOpen.ShowOpen
   filename = dlgOpen.filename

   If dlgOpen.FileTitle <> "" Then
      ' Open file for writing
      Open filename For Random Access Read As #1 _
         Len = recordLength
      cmdOpenFile.Enabled = False  ' Disable button
      cmdNext.Enabled = True
      cmdDone.Enabled = True
   Else
      MsgBox ("You must specify a file name")
   End If
End Sub

Private Sub cmdNext_Click()
   ' Read record from file
   Do
      Get #1, , mUdtClient
   Loop Until EOF(1) Or mUdtClient.accountNumber <> 0
   
   If EOF(1) Then
      cmdNext.Enabled = False
      Exit Sub
   End If
   
   If mUdtClient.accountNumber <> 0 Then
      txtAccount.Text = Str$(mUdtClient.accountNumber)
      txtFirstName.Text = mUdtClient.firstName
      txtLastName.Text = mUdtClient.lastName
      txtBalance.Text = Str$(mUdtClient.balance)
   End If
End Sub

Sub cmdDone_Click()
   Close #1
   cmdOpenFile.Enabled = True
   cmdNext.Enabled = False
   cmdDone.Enabled = False
   txtAccount.Text = ""
   txtFirstName.Text = ""
   txtLastName.Text = ""
   txtBalance.Text = ""
End Sub

Private Sub Form_Terminate()
   Close #1
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -