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

📄 form1.frm

📁 VB源码,是初学者的福因.让你很快掌握VB编程
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "文件读写演示"
   ClientHeight    =   4980
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6555
   LinkTopic       =   "Form1"
   ScaleHeight     =   4980
   ScaleWidth      =   6555
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command6 
      Caption         =   "二进制读出"
      Height          =   375
      Left            =   5520
      TabIndex        =   7
      Top             =   4560
      Width           =   1095
   End
   Begin VB.CommandButton Command5 
      Caption         =   "随机读出"
      Height          =   375
      Left            =   4440
      TabIndex        =   6
      Top             =   4560
      Width           =   1095
   End
   Begin VB.CommandButton Command4 
      Caption         =   "顺序读出"
      Height          =   375
      Left            =   3360
      TabIndex        =   5
      Top             =   4560
      Width           =   1095
   End
   Begin VB.CommandButton Command3 
      Caption         =   "二进制写入"
      Height          =   375
      Left            =   2040
      TabIndex        =   4
      Top             =   4560
      Width           =   1095
   End
   Begin VB.CommandButton Command2 
      Caption         =   "随机写入"
      Height          =   375
      Left            =   960
      TabIndex        =   3
      Top             =   4560
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "顺序写入"
      Height          =   375
      Left            =   -120
      TabIndex        =   2
      Top             =   4560
      Width           =   1095
   End
   Begin VB.TextBox Text2 
      Height          =   4335
      Left            =   3240
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      TabIndex        =   1
      Top             =   120
      Width           =   3255
   End
   Begin VB.TextBox Text1 
      Height          =   4335
      Left            =   0
      MultiLine       =   -1  'True
      TabIndex        =   0
      Top             =   120
      Width           =   3255
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
    Open "c:\test1.txt" For Output Access Write As #1
    Print #1, Text1.Text
    Close #1
End Sub

Private Sub Command2_Click()
    Dim tmpStr As String
    Open "c:\test2.txt" For Random As #1 Len = 32   '32 chars for a line
    j = 1
    For i = 1 To Len(Text1.Text)
        If Mid(Text1.Text, i, 1) = Chr(13) Then
            Put #1, j, tmpStr
            j = j + 1
            tmpStr = ""
        Else
            If Len(tmpStr) < 30 Then
                tmpStr = tmpStr + Mid(Text1.Text, i, 1)
            End If
        End If
    Next
    Put #1, j, tmpStr
    Close #1
End Sub

Private Sub Command3_Click()
    Open "c:\test3.txt" For Binary As #1
    Put #1, , Text1.Text
    Close #1
End Sub

Private Sub Command4_Click()
    Dim tmpStr  As String
    Dim tmpVar As Variant
    Dim i As Integer
    Text2.Text = ""
    Open "c:\test1.txt" For Input Access Read As #1
    i = 1
    Do Until EOF(1)
        tmpVar = Input(1, #1)
        tmpStr = tmpStr + tmpVar
        i = i + 1
    Loop
    Close #1
    Text2.Text = tmpStr
End Sub

Private Sub Command5_Click()
    Dim tmpStr As String
    Text2.Text = ""
    Open "c:\test2.txt" For Random As #1 Len = 32
    j = LOF(1) / 32 + 1
    For i = 1 To j
        Get #1, i, tmpStr
        Text2.Text = Text2.Text & tmpStr & Chr(13)
    Next
    Close #1
End Sub

Private Sub Command6_Click()
    Dim tmpStr  As String
    Dim tmpVar As Byte
    Text2.Text = ""
    Open "c:\test3.txt" For Binary As #1
    For i = 1 To LOF(1)
        Get #1, i, tmpVar
        tmpStr = tmpStr + Chr(tmpVar)
    Next
    Close #1
    Text2.Text = tmpStr
End Sub

Private Sub Form_Load()

End Sub

⌨️ 快捷键说明

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