快捷导航 上传作品

[VB] vb 排序

[复制链接]
梅雷工具箱发表于 2015-6-25 13:10:17 | 显示全部楼层 |阅读模式


排序


添加3个控件分别是 Text1 、Text2 和 Command1

在同目录 新建两个文件 111.txt 和 222.txt

Private Sub Command1_Click()
Dim Arry() As String

    Dim i As Long, j As Long
    Dim x As String, y As String
   
    i = 1
    ReDim Preserve Arry(i) As String
    Open App.Path & "\111.txt" For Input As #1
    While Not EOF(1)
        Line Input #1, Arry(i)
        i = i + 1
        ReDim Preserve Arry(i) As String
    Wend
    ReDim Preserve Arry(i - 1) As String
    Close #1
   
    For i = 1 To UBound(Arry)
        For j = 1 To UBound(Arry)
            If j < UBound(Arry) Then
                If Val(Arry(j)) > Val(Arry(j + 1)) Then
                    x = Arry(j)
                    y = Arry(j + 1)
                    Arry(j) = y
                    Arry(j + 1) = x
                End If
            End If
        Next
    Next
        
    Open App.Path & "\222.txt" For Output As #1
    For i = 1 To UBound(Arry)
        Print #1, Arry(i)
    Next i
    Close #1
   
    取读文件位置 = App.Path & "\222.txt"

Open 取读文件位置 For Input As #1      '【打开要取读的文件】
Do While Not EOF(1)                    '【循环每一行】
Line Input #1, temp                    '【去读内容赋值】
Text2 = Text2 & temp & vbCrLf
Loop                                   '【结束循环】
Close #1
End Sub


Private Sub Form_Load()
取读文件位置 = App.Path & "\111.txt"

Open 取读文件位置 For Input As #1      '【打开要取读的文件】
Do While Not EOF(1)                    '【循环每一行】
Line Input #1, temp                    '【去读内容赋值】
Text1 = Text1 & temp & vbCrLf
Loop                                   '【结束循环】
Close #1
End Sub



_____________________________________________________________________________ _

中磊UG二次开发教程 梅雷著 qq1821117007
学UG就上UG网 http://www.9sug.com/
就上UG网淘宝直营店
回复

使用道具 评分 举报

您需要登录后才可以回帖 登录 | 注册UG网

本版积分规则