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

📄 读写随机文件.frm

📁 vb编程+从基础到实践光盘代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6225
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   10.5
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   6225
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "读文件"
      Height          =   495
      Left            =   3600
      TabIndex        =   1
      Top             =   2400
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "写文件"
      Height          =   495
      Left            =   1200
      TabIndex        =   0
      Top             =   2400
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Base 1
Private Type student          '声明自定义类型
  StrName As String * 8
  BlnSex As Boolean
  DtmBirth As Date
  IntMark(1 To 2) As Integer
End Type
Private Sub Command1_Click()
  Dim stu(2) As student                    '声明自定义类型的数组
  Open "c:\wd.txt" For Random As #1 Len = Len(stu(1)) '以随机方式打开文件
  stu(1).StrName = "张三"                '给数组元素赋值
  stu(1).DtmBirth = #2/1/1984#
  stu(1).BlnSex = True
  stu(1).IntMark(1) = 90
  stu(1).IntMark(2) = 85
  stu(2).StrName = "李四"
  stu(2).DtmBirth = #12/11/1980#
  stu(2).BlnSex = False
  stu(2).IntMark(1) = 95
  stu(2).IntMark(2) = 86
  Put #1, 1, stu(1)              '把数组元素写入文件中
  Put #1, 2, stu(2)
  Close 1
End Sub

Private Sub Command2_Click()
  Dim stu As student                '声明自定义类型的变量
  Open "c:\wd.txt" For Random As #1 Len = Len(stu)    '打开随机文件
  Get #1, , stu        '读入一个记录并显示内容
  Print stu.StrName, stu.BlnSex, stu.DtmBirth, stu.IntMark(1), stu.IntMark(2)
  Get #1, , stu        '读入另一个记录并显示内容
  Print stu.StrName, stu.BlnSex, stu.DtmBirth, stu.IntMark(1), stu.IntMark(2)
Close 1
End Sub

Private Sub Form_Load()

End Sub

⌨️ 快捷键说明

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