?? 訪問隨機文件.frm
字號:
VERSION 5.00
Begin VB.Form Form1
Caption = "例[12-5]訪問隨機文件"
ClientHeight = 2490
ClientLeft = 60
ClientTop = 345
ClientWidth = 3135
LinkTopic = "Form1"
ScaleHeight = 2490
ScaleWidth = 3135
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text3
Height = 495
Left = 1440
TabIndex = 6
Top = 1320
Width = 1455
End
Begin VB.TextBox Text2
Height = 495
Left = 1440
TabIndex = 4
Top = 720
Width = 1455
End
Begin VB.TextBox Text1
Height = 495
Left = 1440
TabIndex = 2
Top = 120
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "讀一條記錄"
Height = 495
Left = 780
TabIndex = 0
Top = 1920
Width = 1575
End
Begin VB.Label Label3
Caption = "語文成績:"
Height = 375
Left = 240
TabIndex = 5
Top = 1440
Width = 975
End
Begin VB.Label Label2
Alignment = 2 'Center
Caption = "姓 名:"
Height = 375
Left = 240
TabIndex = 3
Top = 840
Width = 975
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "文件長度:"
Height = 375
Left = 240
TabIndex = 1
Top = 240
Width = 975
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim person1 As ID
Dim i As Integer
Cls
Open "d:\Score.dat" For Random As #1 Len = Len(person1)
Text1.Text = LOF(1)
Randomize
i = Int(4 * Rnd + 1) 'i的取值范圍為1~4
Get #1, i, person1 '讀第i條記錄
Text2.Text = person1.Name
Text3.Text = person1.Score
Close #1
End Sub
Private Sub Form_Click()
'該事件過程建立d:\Score.dat隨機文件
Dim person1 As ID '聲明自定義類型變量
Open "d:\Score.dat" For Random As #1 Len = Len(person1) '建立隨機文件
person1.Name = "張強"
person1.Score = 87
Put #1, 1, person1 '寫入1號文件的第1條記錄
person1.Name = "李小明"
person1.Score = 97
Put #1, 2, person1 '寫入1號文件的第2條記錄
person1.Name = "王平"
person1.Score = 83
Put #1, 3, person1 '寫入1號文件的第3條記錄
person1.Name = "趙志鋼"
person1.Score = 72
Put #1, 4, person1 '寫入1號文件的第4條記錄
Close #1
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -