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

📄 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         =   "Write to 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 cmdEnter 
      Caption         =   "Add 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 Write"
      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.5
' Writing data to 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()
   cmdEnter.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 Write As #1 _
         Len = recordLength
      
      cmdOpenFile.Enabled = False  ' Disable button
      cmdEnter.Enabled = True
      cmdDone.Enabled = True
   Else
      MsgBox ("You must specify a file name")
   End If
End Sub

Private Sub cmdEnter_Click()
   mUdtClient.accountNumber = Val(txtAccount.Text)
   mUdtClient.firstName = txtFirstName.Text
   mUdtClient.lastName = txtLastName.Text
   mUdtClient.balance = Val(txtBalance.Text)
   
   ' Write record to file
   Put #1, mUdtClient.accountNumber, mUdtClient
   
   Call ClearFields
End Sub

Sub cmdDone_Click()
   Close #1
   cmdOpenFile.Enabled = True
   cmdEnter.Enabled = False
   cmdDone.Enabled = False
End Sub

Private Sub Form_Terminate()
   Close #1
End Sub

Private Sub ClearFields()
   txtAccount.Text = ""
   txtFirstName.Text = ""
   txtLastName.Text = ""
   txtBalance.Text = ""
End Sub

⌨️ 快捷键说明

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