找回密码
 加入
搜索
查看: 2197|回复: 2

[AU3基础] 从INI文件中按要求归类

[复制链接]
发表于 2011-4-4 23:31:48 | 显示全部楼层 |阅读模式
刚学AU3没几天,想请教一个基础的问题:
这是文件main.ini的一部分,
[main]
name1=刘德华
age1=44
sex1=男
address1=香港
name2=宋慧乔
age2=34
sex2=女
address2=韩国
name3=范冰冰
age3=32
sex3=女
address3=中国
name4=成龙
age4=58
sex4=男
address4=香港
name5=权相宇
age5=38
sex5=男
address5=韩国
我现在想点击button1时,在listview中显示韩国人,点击button2时,在listview中显示香港人,
请教高手,代码应如何编写!谢谢!
发表于 2011-4-5 07:29:02 | 显示全部楼层
你这个应该将美各国家列一个字段。
而且每个人的信息最好在一个键值中,用分隔符隔开。
[香港]
1=刘德华,44,男
2=成龙,58,男
……
发表于 2011-4-5 09:29:11 | 显示全部楼层
本帖最后由 lixiaolong 于 2011-4-5 10:20 编辑

回复 1# duyan

看看这个可以不?
$var = IniReadSection(@DesktopDir & '\main.ini', "main")
$address = '韩国'
For $i = 1 To $var[0][0]
        If $var[$i][1] = $address Then
                $i += 1
                MsgBox(4096, "", $var[$i][1] & @CRLF & $var[$i + 1][1] & "岁" & @CRLF & $var[$i + 2][1])
                $i += 1
        EndIf
Next
main.ini
[main]
address0=韩国
name1=刘德华
age1=44
sex1=男
address1=香港
name2=宋慧乔
age2=34
sex2=女
address2=韩国
name3=范冰冰
age3=32
sex3=女
address3=中国
name4=成龙
age4=58
sex4=男
address4=香港
name5=权相宇
age5=38
sex5=男
当练习吧
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $var = IniReadSection(@DesktopDir & '\main.ini', "main")
Global $address = '韩国'

GUICreate($address & '人', 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; 设置背景色

$listview = GUICtrlCreateListView("姓名  |年龄|性别  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("查看选中项目的数据", 40, 170, 120, 20)
Global $item1 = GUICtrlCreateListViewItem("", $listview)
Global $item2 = GUICtrlCreateListViewItem("", $listview)
Global $item3 = GUICtrlCreateListViewItem("", $listview)
GUISetState()
address()

Do
        $msg = GUIGetMsg()

        Select
                Case $msg = $button
                        MsgBox(0, "listview 项目", GUICtrlRead(GUICtrlRead($listview)), 2)
                Case $msg = $listview
                        MsgBox(0, "listview", "被点击列的索引值 = " & GUICtrlGetState($listview), 2)
        EndSelect
Until $msg = $GUI_EVENT_CLOSE

Func address()
        Local $s = 1
        For $i = 1 To $var[0][0]
                If $var[$i][1] = $address Then
                        $i += 1
                        GUICtrlSetData(Eval('item' & $s), $var[$i][1] & '|' & $var[$i + 1][1] & '|' & $var[$i + 2][1])
                        $s += 1
                        $i += 4;这个可以去掉.
                EndIf
        Next
EndFunc   ;==>address
如果想显示中国人只把 Global $address = '韩国' 改成 Global $address = '中国' 就可以了.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 11:14 , Processed in 0.081734 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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