Jump to content
Sign in to follow this  
ShikiPiki

Having trouble with arrays..

Recommended Posts

ShikiPiki

I am currently trying to debug my code and i cannot find a solution to this issue. on line 103 i have a consolewrite check where i say:

ConsoleWrite($itemData[$iIndex[$jj]][0]); & " " & $itemData[$itemIndex[$jj]][1])

I commented out the second part to try to figure out why it is giving me an error in the first section. The error which i recieve is : Array variable has incorrect number of subscripts or subscript dimension range exceeded. However when i check the value of $itemIndex[$jj] it is between 0 and 9, which checks out when i check $itemData. I've tried putting parenthesize around it thinking maybe it was a grouping issue... either way I have no idea why it's giving me this error... Any help would be appreciated

Thanks

-ShikiPiki

 

#include <GUIConstantsEx.au3>
#include <file.au3>
#include <array.au3>
#include <Excel.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <GuiTreeView.au3>
#include <GuiConstants.au3>

HotKeySet("{PAUSE}", "EndScript")

Local $sFilePath1 = @ScriptDir & "\test.csv"
If Not FileExists($sFilePath1) Then
   MsgBox(16, '', $sFilePath1 & 'DOES NOT exists')
   Exit
EndIf
 
 Opt("MustDeclareVars", 1)

Global Const $CSVFILE = $sFilePath1
Global Const $DELIM = "," ;the delimiter in the CSV file
Global  $arrContent, $arrLine, $res = 0,  $itemHandle, $iIndex

$res = _FileReadToArray($CSVFILE, $arrContent)
 
Setup()
Func Setup()
   Local $treeView, $Pt01to05, $Pt06to10
   Local $cancel, $addItem, $calculate
   Local $msg, $selected, $item
   Global $listView, $cp, $calculating
   global $itemData[$arrContent[0]][5], $test[$arrContent[0]]
   global $itemIndex[$arrContent[0]], $iIndex[$arrContent[0]]
   $iIndex[0]=1
   GUICreate("Set-up", 375, 300)
   GUICtrlCreateLabel("Items Added", 110, 5, 100, 20, $SS_CENTER)
   $listView = GUICtrlCreateList("", 110, 25, 100, 150)
   GUICtrlCreateLabel("Part Number", 220, 5, 150, 20, $SS_CENTER)
   $cp = GUICtrlCreateInput("", 220, 25, 150, 20)
   GUICtrlCreateLabel("Part sub-Number", 220, 125, 150, 20, $SS_CENTER)
   $calculating = GUICtrlCreateInput("", 220, 150, 150, 20)
   
   $treeView = GUICtrlCreateTreeView( 5, 5, 100, 245, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, _
      $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
   $Pt01to05 = GUICtrlCreateTreeViewItem("Product Section 1 - 5", $treeView)
   GUICtrlSetColor(-1, 0x0000C0)
   $Pt06to10 = GUICtrlCreateTreeViewItem("Product Section 6- 10", $treeView)
   GUICtrlSetColor(-1, 0x0000C0)
  If $res = 1 Then
    For $ii = 1 To $arrContent[0]
        $arrLine = StringSplit($arrContent[$ii], $DELIM)
         If $arrLine[1] < 6 Then
            $itemIndex[$ii-1] = GUICtrlCreateTreeViewItem("No. " & $arrLine[1] & ". " & $arrLine[2], $Pt01to05)
            For $jj = 1 To 2
               $itemData[$ii-1][$jj-1]=$arrLine[$jj]
            Next
         Elseif $arrLine[1] > 5 And $arrLine[1] < 11 Then
            $itemIndex[$ii-1] = GUICtrlCreateTreeViewItem("No. " & $arrLine[1] & ". " & $arrLine[2], $Pt06to10)
            For $jj = 1 To 2
               $itemData[$ii-1][$jj-1]=$arrLine[$jj]
            Next
         EndIf
      Next 
   Else
       MsgBox(48, "", "Error opening file! "& $sFilePath1 )
    EndIf 
;~  ConsoleWrite($itemData[9][1]) ; <--- works fine
;~  _ArrayDisplay($itemData) ; Check data
    
   $cancel = GUICtrlCreateButton("&Cancel", 300, 280, 70, 20)
   $addItem = GUICtrlCreateButton("&Add", 5, 250, 70, 50)
   GUICtrlSetFont(-1, 15, 800)
   $calculate = GUICtrlCreateButton("Ca&lculate!", 110, 180, 250, 90)
   GUICtrlSetFont(-1, 30, 600)
   
   GUISetState()
   While 1
      $msg = GUIGetMsg()
      Select 
         Case $msg = $cancel Or $msg = $GUI_EVENT_CLOSE
            ExitLoop
         Case $msg = $addItem
            $selected = GUICtrlRead($treeView)
            If $selected = 0 Then
               MsgBox(64, "Error 01", "Error 01: No items currently selected")
            Else
               $item = GUICtrlRead($selected, 1)
               GUICtrlSetData($listView, $item)
               $itemHandle = _GUICtrlTreeView_GetSelection($treeView)
               For $jj = 1 To $arrContent[0]
                  If $itemHandle = _GUICtrlTreeView_GetItemHandle($treeView, $itemIndex[$jj-1]) Then
                     $iIndex[$iIndex[0]] = $jj-1
                     $iIndex[0] =($iIndex[0]+1)
                     ExitLoop
                  EndIf
               Next
            EndIf
         Case $msg = $calculate
            ReDim $iIndex[$iIndex[0]]
            For $jj = 1 To $iIndex[0]-1
;~             ConsoleWrite($iIndex[$jj] & @LF)
               ConsoleWrite($itemData[$iIndex[$jj]][0]); & " " & $itemData[$iIndex[$jj]][1]) ;<--- does not work
;~             ConsoleWrite($itemData[9][1]);<-- works fine
            Next
;~          Call("Optimizer")
      EndSelect
   WEnd
   GUIDelete()
EndFunc

Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx
    For $idx = $hidestart To $hideend
        GUICtrlSetState($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState($idx, $GUI_SHOW)
    Next
EndFunc
Edited by ShikiPiki

Thanks! -ShikiPiki

Share this post


Link to post
Share on other sites
BrewManNH

I think it's because of the way you're accessing the $iIndex elements in the additem section of the while loop, but it's so confusing what exactly you're trying to do that it's really hard to follow your logic in there.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
ShikiPiki

I think it's because of the way you're accessing the $iIndex elements in the additem section of the while loop, but it's so confusing what exactly you're trying to do that it's really hard to follow your logic in there.

Sorry i know it is a bit of a mess... i've been takign snippets of codes here and there from differnt people and help files to put this together so it is very messy. In the index part, when i press the add button it adds the item name selected to the list as well as save the index of the item in the tree. So when i select no.5 itll add the name to the list as well as the fact that the item was the 5th item in the tree. The reason i do this is so that i can go back later in my itemData and pull out information that is not in the name (information in the CSV that is not dispalyed in name). Also after tinkering with my code per your suggestion, it is workign as intended now and i only have to code up an optimization function. The issue was really just that this whole thing was a mess and keeping the code straight was kind of difficult.

This is my first time using the GUI tree as well as really getting my hands on arrays and autoit so i'm sorry that this is a whole mess and if my questions seem unclear or make you face palm

Thanks!

-ShikiPiki


Thanks! -ShikiPiki

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×