zoukankan      html  css  js  c++  java
  • QTP的那些事—VBS中的字段冒泡排序

    http://demon.tw/copy-paste/vbs-scripting-dictionary-ksort.html
    
    Option Explicit
    
    Function fnCompare(key1, key2)
        If CInt(key1) > CInt(key2) Then
            fnCompare = 1
        ElseIf CInt(key1) < CInt(key2) Then
            fnCompare =  - 1
        Else
            fnCompare = 0
        End If
    End Function
    
    Function Sort(dict)
        Dim i,j, temp
        Dim keys,items
        Dim t ' 临时备份字典
        Set t = WSH.CreateObject("Scripting.Dictionary")
    
        keys = dict.Keys
        items = dict.Items
    
        ' 下面复制原字典到备份字典中
        For i = 0 To  dict.Count - 1
            t.Add keys(i),items(i)
        Next
    
        ' 下面交换键key数组
        For i = 0 To  dict.Count - 1
            For j = i + 1 To dict.Count - 1
                If fnCompare(keys(i), keys(j)) > 0 Then
                    temp = keys(i)
                    keys(i) = keys(j)
                    keys(j) = temp
                End If
            Next
        Next
    
        dict.RemoveAll ' 清除原数组
    
        ' 读取已经排好序的key数组
        ' 并添加到清空后的目标字典中
        For i = 0 To UBound(keys)
            dict.Add keys(i), t.Item(keys(i))
        Next
    
        ' 销毁备份字典
        t.RemoveAll
        Set t = Nothing
    End Function
  • 相关阅读:
    [Camtasia报错]An error occurred in the Recorde System Audio setup Failed
    [Oracle报错]RMAN-12005: error during channel cleanup/ORA-19550: cannot ...
    [Teamviewer报错]现在无法捕捉屏幕画面。这可能是由于快速的...
    [SVN技能]SVN服务迁移(Windows-Linux)
    [RabbitMQ技能]安装部署单节点RabbitMQ
    运算符的那些事
    java之连接数据库之JDBC访问数据库的基本操作
    面向对象编程之OC
    集合
    面向对象
  • 原文地址:https://www.cnblogs.com/seniortestingdev/p/2523778.html
Copyright © 2011-2022 走看看