本帖最后由 cashiba 于 2017-5-22 11:10 编辑
回复 cashiba
chzj589 发表于 2017-5-22 08:55
感谢chzj589大侠!用到了三维数组,这个方法估计代码比较简单,我从来没用过三维数组,感觉好三度空间好复杂....
我用字符串处理暂时达到目的了,也挺绕眼睛的,多重循环。你看看用三维数组怎样弄成下面的样子:
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Excel.au3>
#include <File.au3>
#include <GuiTreeView.au3>
#include <String.au3>
Local $ofile = @ScriptDir & "\Tvassigns.ini"
If not FileExists($ofile) Then
MsgBox(4096,"","缺少数据源文件")
exit
endif
Local $Sty = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
local $Gui=GUICreate("TV", 840, 700)
Local $idT = GUICtrlCreateTreeView(6, 6, 360, 680,$Sty,$WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
Local $hia, $hib,$hic, $hid, $idT
Local $aLay=IniReadSectionNames($oFile)
If @error Then Exit
_GUICtrlTreeView_BeginUpdate($idT)
$arr=IniReadSection($oFile, "0")
for $a=1 to $arr[0][0]
$hia = _GUICtrlTreeView_Add($idT, 0, OfSplits($arr[$a][1],"|",1))
$brr=IniReadSection($oFile, "1")
For $b=1 To $brr[0][0]
If OfSplits($brr[$b][1],"|",0)=OfSplits($arr[$a][1],"|",1) Then
$hib = _GUICtrlTreeView_AddChild($idT, $hia,OfSplits($brr[$b][1],"|",1))
$crr=IniReadSection($oFile, "2")
For $c=1 To $crr[0][0]
If OfSplits($crr[$c][1],"|","0|1")=$brr[$b][1] Then
$hic = _GUICtrlTreeView_AddChild($idT, $hib,OfSplits($crr[$c][1],"|",2))
$drr=IniReadSection($oFile, "3")
For $d=1 To $drr[0][0]
If OfSplits($drr[$d][1],"|","0|1|2")=$crr[$c][1] Then
$hid = _GUICtrlTreeView_AddChild($idT, $hic,OfSplits($drr[$d][1],"|",3))
EndIf
Next
EndIf
Next
EndIf
Next
next
_GUICtrlTreeView_EndUpdate($idT)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func OfSplits($str,$php,$num)
Local $Srr=StringSplit($str,$php,3)
If StringInStr($num,"|")=0 Then
If $num<0 Or $num>(UBound($Srr)-1) Then
MsgBox(4096,"","函数参数$n超限")
Else
Return $srr[$num]
EndIf
Else
Local $n
Local $Nrr=StringSplit($num,"|",3)
For $n In $Nrr
If $n<0 Or $n>(UBound($Srr)-1) Then
MsgBox(4096,"","函数参数$n超限")
EndIf
Next
Local $txt=""
Local $j=""
For $i=0 To (UBound($Nrr)-1)
$j=$Nrr[$i]
$txt=$txt&$srr[$j]&$php
Next
$txt=StringLeft($txt,(StringLen($txt)-StringLen($php)))
Return $txt
EndIf
EndFunc
|