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

📄 form1.frm

📁 vb 的例子
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "排序"
   ClientHeight    =   3195
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command1 
      Caption         =   "排序"
      Height          =   450
      Left            =   3240
      TabIndex        =   0
      Top             =   2400
      Width           =   1215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Option Base 1

Private Sub Command1_Click()
    Dim n As Integer, i() As Integer         ' 声明动态数组
    Dim int1 As Integer, int2 As Integer, int3 As Integer
    '从文件中读入数据
    Open "c:\old.txt" For Input As 1                      '打开文件
    n = 0
    Do While Not EOF(1)                             ' 检测是否到文件尾
        n = n + 1
        ReDim Preserve i(n)                  ' 重新声明动态数组
        Input #1, i(n)                       ' 读入一个整数
    Loop
    Close 1                                             ' 关闭文件
'    '对数据进行排序(选择法)
'    For int1 = 1 To n - 1
'        For int2 = int1 + 1 To n
'            If i(int1) > i(int2) Then           ' 比较大小
'                int3 = i(int1)                  ' 交换数据
'                i(int1) = i(int2)
'                i(int2) = int3
'            End If
'        Next
'    Next
    '对数据进行排序(冒泡法)
    For int1 = n To 2 Step -1
        For int2 = 1 To int1 - 1
            If i(int2) > i(int2 + 1) Then         ' 比较大小
                int3 = i(int2)                    ' 交换数据
                i(int2) = i(int2 + 1)
                i(int2 + 1) = int3
            End If
        Next
    Next
    '把排序后的数据写入文件
    Open "c:\new.txt" For Output As 1                           ' 打开文件
    For int1 = 1 To n
        Write #1, i(int1),                          ' 输出到文件
        Print i(int1);                              ' 显示在窗体上
    Next
    Close 1                                             ' 关闭文件
End Sub

⌨️ 快捷键说明

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