?? form1.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 + -