Sign in to follow this  
Followers 0
PcExpert

Array troubles again

7 posts in this topic

Hi all,

I got some trouble with the following.

I'll first post my code:

Dim $docent_array[1]

$docent_array = _FileListToArray("Docenten", "*.ini", 1)

For $t = 0 To $docent_array[0]
ReDim $docent_array[$docent_array[0]]
Next

 $left = 45
    For $u = 0 To 5
        $top2 = 210
        For $o = 1 To 5
            $l = $u * 5 + $o
           ; If StringLen($docent_array[$l]) > 2 Then
                $dcCheckBox[$l] = GUICtrlCreateCheckbox("dc" & $l, $left, $top2, 50, 20) 
                $count2 += 1
                $top2 += 20
            ;EndIf
        Next
        $left += 65
    Next

    For $a = 1 To $count2
        If $docent_array[$a] <> "" Then
            GUICtrlSetData($dcCheckBox[$a], $docent_array[$a])
        EndIf
    Next

As you see, its not the full code just the part this is about, I am getting errors about the array:

'Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If $docent_array[$a] <> "" Then

If ^ ERROR'

Its probably because of the subscripts, as you can see its currently 1. I thought to fix the error by redimming the array, But didnt get me much further. I know that the array contains information (tested with _ArrayDisplay()).

Does somebody know how to solve this issue?

Thank you!

Share this post


Link to post
Share on other sites



I don't yet understand some parts of the code but I believe that these are the root of the problem:

For $t = 0 To $docent_array[0]
ReDim $docent_array[$docent_array[0]]
Next

I don't see the point why you're using this loop, and by the way it's ReDim $docent_array[$docent_array[0]+1] unless you want to resize it to one less than the original array size.

Also, I think it's required to see if $count2 is bigger than $docent_array[0] before processing this loop.

At last, you don't need to use declare $docent_array as an array, let _FileListToArray do that for you.

-Just my notes. ;]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks Authenticity. $count2 was much bigger than it should be, going to fix it:).

Edited by PcExpert

Share this post


Link to post
Share on other sites

PcExpert,

Hello again!

The problem is that your $l loop is running from 1 to $u * 5 + $o which means 1 to 30. But your $docent_array could well be less than that. So as soon as $l is higher than the top value of $docent_array > error.

You need to put another If to stop this:

For $o = 1 To 5
    $l = $u * 5 + $o
    If $l < $docent_array[0] + 1 Then 
        ConsoleWrite("Here " & $l & @CRLF)
        If StringLen($docent_array[$l]) > 2 Then
            $dcCheckBox[$l] = GUICtrlCreateCheckbox("dc" & $l, $left, $top2, 100, 20) 
            $count2 += 1
            $top2 += 20
        EndIf
    EndIf
Next

Try that and see if it works. You can definitely remove the entire ReDim looping stuff, by the way!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Melba, you're great! Thanks for noticing this so fast. All the problems have gone now :P.

Share this post


Link to post
Share on other sites

PcExpert,

The first reply was from Authenticity - you might like to edit your post #3!

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks for the suggestions Melba, I knew something was wrong with that post. FIXED! Sorry Authenticity

Edited by PcExpert

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  
Followers 0