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

[AU3基础] (已解决)数组维数报错!

  [复制链接]
发表于 2010-12-31 00:24:48 | 显示全部楼层 |阅读模式
本帖最后由 yarsye 于 2010-12-31 17:47 编辑

以下是解决好的代码 以前的数组越位了 改成$array2[$i+1][0]里面加上个1就OK 了
谢谢各位了 
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>

Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
Global $array1[2][2], $array2[2][2], $array3[2][2], $inipath, $inivalue, $readini
$inipath = @DesktopDir & '\test.ini'
$inivalue = ''

$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 568, $iStyle, $WS_EX_CLIENTEDGE)
Recursion(@ProgramFilesDir, '')
GUISetState()

$readini = IniReadSection($inipath , 'section1')
If @error Then 
        MsgBox(4096, "", "错误, 不是 INI 文静.")
Else
        For $k = 1 To $readini[0][0]
                MsgBox(0,1,'key'&$readini[$i][0] & @CRLF & 'value' & $readini[$i][1])
        Next
EndIf

Do
Until GUIGetMsg() = -3

Func Recursion($current, $flag)
        Local $i = 0, $j = 0
        If Not FileExists($inipath) Then
                IniWrite($inipath, 'section', 'key', 1)
                $inivalue = IniRead($inipath, 'section', 'key', '')
        Else
                $inivalue = IniRead($inipath, 'section', 'key', '')
                $inivalue += 1
                IniWrite($inipath, 'section', 'key', $inivalue)
                $inivalue = IniRead($inipath, 'section', 'key', '')
        EndIf
        If $flag = '' Then $item1 = GUICtrlCreateTreeViewItem($current, $hTreeView)
        Local $search = FileFindFirstFile($current & "\*.*")
        While 1
                Dim $file = FileFindNextFile($search)
                If @error Or StringLen($file) < 1 Then ExitLoop
                If StringInStr(FileGetAttrib($current & "" & $file), "D") And ($file <> "." Or $file <> "..") Then
                        If $flag <> '' Then $item1 = $flag
                        $item2 = GUICtrlCreateTreeViewItem($file, $item1)
                        $i += 1
                        ReDim $array2[$i + 1][2]
                        $array2[$i][0] = $item2
                        IniWrite($inipath, 'section1', 'key' & $i, $array2[$i][0])
                        Recursion($current & "" & $file, $item2)
                Else
                        If $flag <> '' Then $item1 = $flag
                        $item3 = GUICtrlCreateTreeViewItem($file, $item1)
                        $j += 1
                        ReDim $array3[$j + 1][2]
                        $array3[$j][0] = $item3
                        IniWrite($inipath, 'section2', 'key' & $j, $array3[$j][0])
                EndIf
        WEnd
        Return
EndFunc   ;==>Recursion
发表于 2010-12-31 01:14:32 | 显示全部楼层
回复 1# yarsye
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>

Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
Global $item1[2][2] , $item2[2][2] , $item3[2][2] , $file , $inivalue , $inipath
$inipath = @DesktopDir & '\test.ini'
$inivalue = ''

$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)

$hTreeView = GUICtrlCreateTreeView( 2, 2, 396, 568,$iStyle, $WS_EX_CLIENTEDGE)
Recursion(@ProgramFilesDir,'')

GUISetState()

Do
Until GUIGetMsg() = -3
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case - 3
                        Exit
;~                 Case $aFitem[0][0] To $aFitem[UBound($aFitem) - 1][0] ;父项目
;~                         If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then ;如果父项目勾选,其下所有子项目全选。
;~                                 $iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
;~                                 For $i = $nMsg To $nMsg + $iSitemNumber
;~                                         GUICtrlSetState($i, $GUI_CHECKED)
;~                                 Next
;~                         Else
;~                                 $iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
;~                                 For $i = $nMsg To $nMsg + $iSitemNumber
;~                                         GUICtrlSetState($i, $GUI_UNCHECKED)
;~                                 Next
;~                         EndIf
;~                         ContinueCase
;~                 Case $it
;~                         $sText = ''
;~                         For $i = 0 To UBound($aSitem) - 1
;~                                 If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i][0]) Then
;~                                         $sText &= '被选项目句柄:' & $aSitem[$i][0] & '   ' & '项目文本:' & $aSitem[$i][1] & @CRLF
;~                                 EndIf
;~                         Next
;~                         If $sText <> '' Then MsgBox(0, '获取被选项目句柄+项目文本', $sText)
        EndSwitch
WEnd

Func Recursion($current, $flag)
        If Not FileExists($inipath) Then 
                IniWrite($inipath,'section','key',3)
                $inivalue = 3
        Else
                $inivalue = IniRead($inipath,'section','key','')
                $inivalue +=1
                IniWrite($inipath,'section','key',$inivalue)
        EndIf
                        
        If $flag = '' Then         
                ReDim $item1[$inivalue][1]
                $item1 = GUICtrlCreateTreeViewItem($current,$hTreeView); _GUICtrlTreeView_Add($hTreeView, 0, $current)
              
                EndIf
        Local $search = FileFindFirstFile($current & "\*.*")

        While 1
                Dim $file = FileFindNextFile($search)
                If @error Or StringLen($file) < 1 Then ExitLoop

                If StringInStr(FileGetAttrib($current & "" & $file), "D") And($file <> "." Or $file <> "..") Then
                        If $flag <> '' Then 
                                ReDim $item1[$inivalue][1]
                                          $item1[$inivalue][0] = $flag
                                ReDim $item2[$inivalue][1] 
                                          $item2[$inivalue][0] = GUICtrlCreateTreeViewItem($file , $item1[$inivalue][0])
                        EndIf
                _ArrayDisplay($item2)
                                MsgBox(0,"l",$inivalue)
                        Recursion($current & "" & $file, $item2[$inivalue][0])
                Else
                        If $flag <> '' Then 
                                ReDim $item1[$inivalue][1] 
                                          $item1[$inivalue][0] = $flag
                                ReDim $item3[$inivalue][1] 
                                          $item3[$inivalue][0]= GUICtrlCreateTreeViewItem($file , $item1[$inivalue][0])
                        EndIf
                EndIf
        WEnd
        Return        
EndFunc   ;==>Recursion
;~ #include <GuiConstantsEx.au3>
;~ #include <GuiTreeView.au3>
;~ #include <WindowsConstants.au3>
;~ #include <EditConstants.au3>
;~ #include <file.au3>
;~ #include <array.au3>

;~ Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

;~ $GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)

;~ $hTreeView = _GUICtrlTreeView_Create($GUI, 2, 2, 396, 568,$iStyle, $WS_EX_CLIENTEDGE)

;~ _GUICtrlTreeView_BeginUpdate($hTreeView)

;~ Recursion(@AppDataCommonDir, '')

;~ _GUICtrlTreeView_EndUpdate($hTreeView)

;~ GUISetState()
;~ Do
;~ Until GUIGetMsg() = -3

;~ Func Recursion($current, $flag)

;~         If $flag = '' Then $item1 = _GUICtrlTreeView_Add($hTreeView, 0, $current)
;~         Local $search = FileFindFirstFile($current & "\*.*")

;~         While 1
;~                 Dim $file = FileFindNextFile($search)
;~                 If @error Or StringLen($file) < 1 Then ExitLoop

;~                 If StringInStr(FileGetAttrib($current & "" & $file), "D") And($file <> "." Or $file <> "..") Then
;~                         If $flag <> '' Then $item1 = $flag
;~                         $item2 = _GUICtrlTreeView_AddChild($hTreeView, $item1, $current & '\' & $file)
;~                         Recursion($current & "" & $file, $item2)
;~                 Else
;~                         If $flag <> '' Then $item1 = $flag
;~                         $item3 = _GUICtrlTreeView_AddChild($hTreeView, $item1, $current & '\' & $file)
;~                 EndIf
;~         WEnd
;~         Return
;~ EndFunc   ;==>Recursion
 楼主| 发表于 2010-12-31 13:16:00 | 显示全部楼层
回复 2# lainline


    提示81行数组越界
发表于 2010-12-31 13:30:09 | 显示全部楼层
ReDim后原来数组里的数值就不存在了,你应该是插入或添加.
btw:像这样一大堆的代码,没几个人有空帮你去分析,你应该将问题简化出来.
 楼主| 发表于 2010-12-31 14:11:02 | 显示全部楼层
问题是 我想在那个递归里面 每调用一次就把数组的值加一 他现在老是提示我数组越界
正在把问题简化 谢谢提醒
发表于 2010-12-31 16:53:01 | 显示全部楼层
做资源管理器?
如果是,试试这个
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#Include <File.au3>

$gui = GUICreate("File Browser", 362, 378, -1, -1)
$tree = GUICtrlCreateTreeView(0, 0, 361, 377)
GUICtrlSetFont(-1,10)
GUICtrlSetColor($tree, 0x00FF00)
GUICtrlSetBkColor($tree,0x000000)

$hImage = _GUIImageList_Create(16, 16, 5, 2)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 54)
_GUICtrlTreeView_SetNormalImageList($tree, $hImage)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$root = _GUICtrlTreeView_AddChild($tree,"","C:\",0)
$root = _GUICtrlTreeView_AddChild($tree,"","D:\",0)
GUISetState(@SW_SHOW)
$folder = DriveGetDrive( "all" )


While 1
    $msg = GUIGetMsg()
    If $msg= -3 Then ExitLoop
WEnd

Func _SearchFolder($folder,$parent,$level=0)
    If $level >= 1 Then Return
    $files = _FileListToArray($folder,"*",1)
    $folders = _FileListToArray($folder,"*",2)
    _FolderFunc($folders,$folder,$parent,$level)
    _FileFunc($files,$parent)
EndFunc

Func _FileFunc($files,$parent)
    For $i = 1 To UBound($files)-1
        _GUICtrlTreeView_AddChild($tree,$parent,$files[$i],1,1)
    Next
EndFunc

Func _FolderFunc($folders,$folder,$parent,$level)
    For $i = 1 To UBound($folders)-1
        $parentitem = _GUICtrlTreeView_AddChild($tree,$parent,$folders[$i],0)
        _SearchFolder($folder & "\" & $folders[$i],$parentitem,$level+1)
    Next   
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $hWndTreeView = GUICtrlGetHandle($tree)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeView
            Switch $iCode
                Case -451
                    $item = _GUICtrlTreeView_GetSelection($hWndTreeView)
                    $root = $item
                    If _GUICtrlTreeView_GetChildCount($hWndTreeView,$item) <= 0 Then
                        $txt = _GUICtrlTreeView_GetText($hWndTreeView,$item)
                        Do
                            $parent = _GUICtrlTreeView_GetParentHandle($hWndTreeView,$item)
                            If $parent <> 0 Then
                                $txt = _GUICtrlTreeView_GetText($hWndTreeView,$parent) & "\" & $txt
                                $item = $parent
                            EndIf
                        Until $parent = 0
                        _SearchFolder($txt,$root)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
 楼主| 发表于 2010-12-31 17:44:56 | 显示全部楼层
回复 6# 3mile

非常感谢!
基本上这个问题 我已经解决啦 开始着手下一步了 呵呵 谢谢了 不过我还是会研究下你的代码的 
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <file.au3>
#include <array.au3>

Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
Global $array1[2][2], $array2[2][2], $array3[2][2], $inipath, $inivalue, $readini
$inipath = @DesktopDir & '\test.ini'
$inivalue = ''

$GUI = GUICreate("(UDF Created) TreeView Create", 400, 640)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 568, $iStyle, $WS_EX_CLIENTEDGE)
Recursion(@ProgramFilesDir, '')
GUISetState()

$readini = IniReadSection($inipath , 'section1')
If @error Then 
        MsgBox(4096, "", "错误, 不是 INI 文静.")
Else
        For $k = 1 To $readini[0][0]
                MsgBox(0,1,'key'&$readini[$i][0] & @CRLF & 'value' & $readini[$i][1])
        Next
EndIf

Do
Until GUIGetMsg() = -3

Func Recursion($current, $flag)
        Local $i = 0, $j = 0
        If Not FileExists($inipath) Then
                IniWrite($inipath, 'section', 'key', 1)
                $inivalue = IniRead($inipath, 'section', 'key', '')
        Else
                $inivalue = IniRead($inipath, 'section', 'key', '')
                $inivalue += 1
                IniWrite($inipath, 'section', 'key', $inivalue)
                $inivalue = IniRead($inipath, 'section', 'key', '')
        EndIf
        If $flag = '' Then $item1 = GUICtrlCreateTreeViewItem($current, $hTreeView)
        Local $search = FileFindFirstFile($current & "\*.*")
        While 1
                Dim $file = FileFindNextFile($search)
                If @error Or StringLen($file) < 1 Then ExitLoop
                If StringInStr(FileGetAttrib($current & "" & $file), "D") And ($file <> "." Or $file <> "..") Then
                        If $flag <> '' Then $item1 = $flag
                        $item2 = GUICtrlCreateTreeViewItem($file, $item1)
                        $i += 1
                        ReDim $array2[$i + 1][2]
                        $array2[$i][0] = $item2
                        IniWrite($inipath, 'section1', 'key' & $i, $array2[$i][0])
                        Recursion($current & "" & $file, $item2)
                Else
                        If $flag <> '' Then $item1 = $flag
                        $item3 = GUICtrlCreateTreeViewItem($file, $item1)
                        $j += 1
                        ReDim $array3[$j + 1][2]
                        $array3[$j][0] = $item3
                        IniWrite($inipath, 'section2', 'key' & $j, $array3[$j][0])
                EndIf
        WEnd
        Return
EndFunc   ;==>Recursion
 楼主| 发表于 2011-1-2 11:50:36 | 显示全部楼层
回复 6# 3mile


    研究了你的代码 但是还是有个地方想请教下

代码的62行 case -451
这个451数字 你是如何得到的?

不懂 想请教下 谢谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-10-2 18:22 , Processed in 0.076674 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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