📄 frmreading.frm
字号:
VERSION 5.00
Object = "{C932BA88-4374-101B-A56C-00AA003668DC}#1.1#0"; "MSMASK32.OCX"
Begin VB.Form frmReading
Caption = "Fig. 14.19: Reading from a sequential file"
ClientHeight = 2685
ClientLeft = 2715
ClientTop = 2460
ClientWidth = 4785
LinkTopic = "Form1"
ScaleHeight = 2685
ScaleWidth = 4785
Begin VB.Frame Frame1
Caption = "Account Information"
Height = 2055
Left = 90
TabIndex = 1
Top = 75
Width = 3210
Begin VB.TextBox txtBalance
Height = 375
Left = 1050
Locked = -1 'True
TabIndex = 8
Top = 1545
Width = 1980
End
Begin VB.TextBox txtName
Height = 375
Left = 1050
Locked = -1 'True
TabIndex = 7
Top = 952
Width = 1980
End
Begin MSMask.MaskEdBox mskAccount
Height = 375
Left = 1050
TabIndex = 6
Top = 360
Width = 1980
_ExtentX = 3493
_ExtentY = 661
_Version = 393216
Enabled = 0 'False
Format = "###"
PromptChar = "_"
End
Begin VB.Label lblBalance
Caption = "Balance:"
Height = 390
Left = 135
TabIndex = 4
Top = 1560
Width = 1110
End
Begin VB.Label lblName
Caption = "Last Name:"
Height = 360
Left = 120
TabIndex = 3
Top = 975
Width = 1335
End
Begin VB.Label lblAccount
Caption = "Account:"
Height = 315
Left = 150
TabIndex = 2
Top = 435
Width = 1350
End
End
Begin VB.CommandButton cmdRead
Caption = "Read"
Height = 495
Left = 3465
TabIndex = 0
Top = 1650
Width = 1215
End
Begin VB.Label lblFileName
BorderStyle = 1 'Fixed Single
Height = 345
Left = 90
TabIndex = 5
Top = 2280
Width = 4590
End
End
Attribute VB_Name = "frmReading"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 14.19
' Reading from a sequential text file
Option Explicit ' General declaration
Dim mFileSysObj As New FileSystemObject ' General declaration
Dim mFile As File ' General declaration
Dim mTxtStream As TextStream ' General declaration
Private Sub Form_Load()
' Get the file
Set mFile = mFileSysObj.GetFile("..\clients.dat")
' Open a text stream for writing to the file
Set mTxtStream = mFile.OpenAsTextStream(ForReading)
' Display path in lblFileName
lblFileName.Caption = mFile.Path
End Sub
Private Sub cmdRead_Click()
Dim s As String
On Error GoTo handler ' Set error trap
' Read the data
s = mTxtStream.ReadLine
' Parse String s to get values for MaskEdit
' and TextBoxes
Dim mark1 As Integer, mark2 As Integer
mark1 = 4 ' Location of first space in s
' Place only the String portion representing the
' account in the MaskEdit.
mskAccount.Text = Trim$(Mid$(s, 1, mark1))
' Position to first letter of name
mark1 = mark1 + 1
' Determine location of second space character and
' add 1 to include the space.
mark2 = InStr(mark1, s, " ", vbTextCompare) + 1
' Place only the String portion representing the
' name in the TextBox.
txtName.Text = Trim$(Mid$(s, mark1, mark2 - mark1))
' Place the formatted dollar amount in the TextBox.
' mark2 is positioned at the beginning of the amount.
txtBalance.Text = Format$(Mid$(s, mark2, Len(s) - mark1), _
"Currency")
Exit Sub
handler:
If Err.Number = 62 Then ' EOF error
Call mTxtStream.Close
cmdRead.Enabled = False
lblFileName.Caption = ""
Else
Call MsgBox(Err.Description)
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -