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

📄 editor.frm

📁 读写保存文件的源代码
💻 FRM
字号:
VERSION 2.00
Begin Form Form1 
   Caption         =   "Editor with Common Dialog"
   ClientHeight    =   4020
   ClientLeft      =   1095
   ClientTop       =   1485
   ClientWidth     =   7365
   Height          =   4425
   Left            =   1035
   LinkMode        =   1  'Source
   LinkTopic       =   "Form1"
   ScaleHeight     =   4020
   ScaleWidth      =   7365
   Top             =   1140
   Width           =   7485
   Begin TextBox Text1 
      Height          =   2055
      Left            =   960
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   0
      Top             =   720
      Width           =   5295
   End
   Begin CommandButton Command1 
      Caption         =   "GetFile"
      Height          =   495
      Left            =   960
      TabIndex        =   1
      Top             =   3000
      Width           =   975
   End
   Begin CommandButton Command2 
      Caption         =   "SaveFile"
      Height          =   495
      Left            =   3240
      TabIndex        =   2
      Top             =   3000
      Width           =   975
   End
   Begin CommandButton Command3 
      Caption         =   "Exit"
      Height          =   495
      Left            =   5280
      TabIndex        =   3
      Top             =   3000
      Width           =   975
   End
   Begin CommonDialog CMDialog1 
      Left            =   6480
      Top             =   1320
   End
   Begin Label Label1 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Reads a file into a text box and saves file from the text box. Uses the Common Dialog control to get a file name for Open and Save."
      Height          =   495
      Left            =   720
      TabIndex        =   4
      Top             =   120
      Width           =   6135
   End
End
Option Explicit

Sub Command1_Click ()
    Dim fhandle As Integer
    Dim Fname As String
    Dim TextFromFile As String, NextLine As String, CRLF As String

    CRLF = Chr$(13) + Chr$(10)

    CMDialog1.Filter = "text files (*.txt)|*.txt|All files (*.*)|*.*"
    CMDialog1.InitDir = "c:\vbdemos\fileio"
    CMDialog1.Action = 1
    Fname = CMDialog1.Filename

    If Fname = "" Then
        Exit Sub
    End If

    fhandle = FreeFile
    Open Fname For Input As fhandle
    
    If LOF(fhandle) > 30000 Then
        MsgBox "Your file is too large to edit."
    Else
        Do Until EOF(fhandle)
            Line Input #fhandle, NextLine
            TextFromFile = TextFromFile + NextLine + CRLF
        Loop
    End If

    'Instead of reading the file a line at a time, it could be read
    'in one operation like this:
    'TextFromFile = Input$(fhandle, LOF(fhandle))

    'Put the contents into the text box
    Text1.Text = TextFromFile

    'Once the text is read in, close the file
    Close fhandle
End Sub

Sub Command2_Click ()
    Dim fhandle As Integer
    Dim Fname As String

    fhandle = FreeFile

    'Determine file name to save
    CMDialog1.InitDir = "c:\vbdemos\fileio"
    CMDialog1.Action = 2
    Fname = CMDialog1.Filename
    
    If Fname = "" Then
        Exit Sub
    End If

    'Open the file for output
    Open Fname For Output As fhandle

    'Place the text as is in the file and close the file
    Print #fhandle, Text1.Text
    Close fhandle

End Sub

Sub Command3_Click ()
    Unload form1
End Sub

⌨️ 快捷键说明

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