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

📄 form1.frm

📁 FileSystemObject读写程序
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Form1"
   ClientHeight    =   5055
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6885
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5055
   ScaleWidth      =   6885
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "Write"
      Height          =   255
      Left            =   1200
      TabIndex        =   2
      Top             =   120
      Width           =   735
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Read"
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   120
      Width           =   735
   End
   Begin VB.TextBox Text1 
      Height          =   4335
      Left            =   120
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   0
      Top             =   480
      Width           =   6615
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'首先在"工程"-"引用"-"Microsoft Scripting Runtime"
Dim fso As Scripting.FileSystemObject
Dim ts As TextStream
Private Sub Command1_Click()
On Error Resume Next '防止因读取文件为空文件时出错,所以忽略下面可能的错误
Set fso = New Scripting.FileSystemObject
Set ts = fso.OpenTextFile("test.txt", ForReading, False, TristateUseDefault)
Text1.Text = "" '防止因读取文件为空文件时,下面语句因出错而不执行造成的不更新文本框,因此先清空文本框
Text1.Text = ts.ReadAll()
ts.Close
End Sub
Private Sub Command2_Click()
On Error Resume Next '防止因写入文件为空文件时出错,所以忽略下面可能的错误
Set ts = fso.OpenTextFile("test.txt", ForWriting, True, TristateUseDefault)
ts.Write (Text1.Text)
ts.Close
End Sub

⌨️ 快捷键说明

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