找回密码
 加入
搜索
查看: 4420|回复: 7

[AU3基础] [已解决]listbox去除重复和排序问题

  [复制链接]
发表于 2010-8-19 17:18:10 | 显示全部楼层 |阅读模式
本帖最后由 风行者 于 2010-8-19 20:02 编辑

1.怎样去掉重复的项只保留一个?
2.如何打乱排列顺序?
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("test", 253, 315, 251, 122)
$List1 = GUICtrlCreateList("", 8, 0, 241, 305)
GUICtrlSetData(-1,"a|b|c|d|e|f|b|c|e")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-8-19 17:59:01 | 显示全部楼层
第一个问题,笨办法解决
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("test", 253, 315, 251, 122)
$Button=GUICtrlCreateButton("清理",100,280)
$List1 = GUICtrlCreateList("", 8, 0, 241, 250)
GUICtrlSetData(-1,"a|b|c|d|e|f|b|c|e")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                Case $Button
                                        $number=_GUICtrlListBox_GetCount($List1)
                                        Dim $Array[$number]
                                        For $i=0 To $number-1
                                                $Array[$i]=_GUICtrlListBox_GetText($List1,$i)
                                        Next
                                        $reusl=_ArrayUnique($Array)
                                        _GUICtrlListBox_ResetContent($List1)
                                        $str=_ArrayToString($reusl,"|",1)                                        
                                        GUICtrlSetData($List1,$str)
                                        
        EndSwitch
WEnd

评分

参与人数 2金钱 +40 收起 理由
风行者 + 20 独特元素!,学习了
afan + 20

查看全部评分

发表于 2010-8-19 18:03:52 | 显示全部楼层
本帖最后由 afan 于 2010-8-19 18:08 编辑

用数组比较简单
_ArrayUnique() 即可

试试 _ArraySwap() 循环打乱
发表于 2010-8-19 18:24:25 | 显示全部楼层
#include <Array.au3>

Local $avArray[9] = ['a', 'b', 'c', 'd', 'e', 'f', 'b', 'c', 'e']
_ArrayDisplay($avArray, '原始')
$avArray = _ArrayUnique($avArray) 
_ArrayDelete($avArray, 0)
_ArrayDisplay($avArray, '清理重复')
For $i = 1 to 15
        _ArraySwap($avArray[Random(0, Ubound($avArray) - 1, 1)], $avArray[Random(0, Ubound($avArray) - 1, 1)])
Next
_ArrayDisplay($avArray, '乱序')

评分

参与人数 1金钱 +20 收起 理由
风行者 + 20 学习了

查看全部评分

 楼主| 发表于 2010-8-19 20:02:24 | 显示全部楼层
谢谢两位的帮忙
发表于 2011-2-18 17:46:44 | 显示全部楼层
正是我想要的。占位留看
发表于 2012-11-5 20:06:48 | 显示全部楼层
这个不错啊。
发表于 2018-6-11 19:21:49 | 显示全部楼层
谢谢楼主提供
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 05:41 , Processed in 0.082250 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表