Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

用Access实现对一组字符串进行排序

时 间:2020-10-01 10:02:26
作 者:李志能   ID:29924  城市:文山
摘 要:数组冒泡排序法。
正 文:

Option Compare Database

Private Sub Command0_Click()
    Dim p$, f$, s1$, s2$, k&
    
'    p = CurrentProject.Path & "\Backup\"
'    f = GetAllFileNamesInFolder(p, "|")
    s1 = "2,5,4,8,1,3,7,6"
    s2 = "Everly,Polly,Jocelyn,Alina"
    Me.Text1.Value = s1 & vbCrLf & s2
    Me.Text2.Value = BubbleSort(s1, ",") & vbCrLf & BubbleSort(s2, ",", True)
End Sub
Function BubbleSort(S As String, Delimiter As String, Optional Descend As Boolean) As String  '数组冒泡排序法
    Dim Ar() As String, Last%, i%, j%, Temp$, List$
    Ar = Split(S, Delimiter)
    Last = UBound(Ar)
    If Nz(Descend, "") = "" Then Descend = False
    For i = 0 To Last - 1
        For j = i + 1 To Last
            If Ar(i) > Ar(j) Then
                Temp = Ar(j)
                Ar(j) = Ar(i)
                Ar(i) = Temp
            End If
        Next j
    Next i
    If Not Descend Then
        For i = 0 To UBound(Ar): List = List & Delimiter & Ar(i): Next
    Else
        For i = UBound(Ar) To 0 Step -1: List = List & Delimiter & Ar(i): Next
    End If
    BubbleSort = Mid(List, 2)
End Function

图   示:



Access软件网官方交流QQ群 (群号:54525238)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助