本帖最后由 user3000 于 2012-1-22 16:34 编辑
回复 xyhqqaa
请问一下,我把代码中的改成下面这个也可以实现请问一下这二者有何区别?什么时候 ...
qq271859852 发表于 2012-1-18 10:02
以下代码根据你原有的加工多一点东西, 希望能给你一点启发!
也希望你学习AU3不要太于浮躁, 要打好基础, 不要连 INI 操作都不熟就想着去学习操作数据库之类更复杂的东西了!
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
Local $inifile = @ScriptDir & '\Mydat.ini'
$Form1 = GUICreate("Form1", 245, 438)
$ListView1 = GUICtrlCreateListView("姓名|编号", 24, 16, 209, 209)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
Local $ReadTxt = IniReadSection($inifile, 'Config')
If @error Then
$ListView1_0 = GUICtrlCreateListViewItem("张三|201203", $ListView1)
$ListView1_1 = GUICtrlCreateListViewItem("李四|201204", $ListView1)
$ListView1_2 = GUICtrlCreateListViewItem("王五|201205", $ListView1)
Else
For $i = 1 To $ReadTxt[0][0]
GUICtrlCreateListViewItem($ReadTxt[$i][0] & '|' & $ReadTxt[$i][1], $ListView1)
Next
EndIf
$Input1 = GUICtrlCreateInput("", 51, 232, 177, 21)
$Input2 = GUICtrlCreateInput("", 51, 258, 177, 21)
$Label1 = GUICtrlCreateLabel("姓名", 16, 232, 28, 17)
$Label2 = GUICtrlCreateLabel("编号", 15, 261, 28, 17)
$Button1 = GUICtrlCreateButton("保存", 72, 288, 105, 33)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$data = GUICtrlRead(GUICtrlRead($ListView1))
If $data = '' Then
MsgBox(48, '信息提示', '请先上面任意一条记录! ')
Else
$name = StringRegExpReplace($data, '([^\|]+?)\|.*', '\1')
$Num = StringRegExpReplace($data, '[^\|]+\|([^\|]+)\|', '\1')
; 以上获取名字及编号也可用 StringSplit 来完成!
GUICtrlSetData($Input1, $name)
GUICtrlSetData($Input2, $Num)
IniWrite($inifile, 'Config', $name, $Num)
EndIf
EndSwitch
WEnd
|