Jump to content
Sign in to follow this  
Herb191

Why am I getting this Array error?

Recommended Posts

Herb191

Why do I occasionally get this error when I run this:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $NumberOfadsToRun


$Form1 = GUICreate("", 625, 445, 192, 124)
$NumberOfadsToRun = 10

RandomlyPickAd()
Func RandomlyPickAd()
    Local $avArray[1]
    $AdType = "General ad"
    $avArray[0] = ""
    
    ; Looks for all text files in directory
    $search = FileFindFirstFile("C:\" & $AdType & "\*.txt")

    ; Check if the search was successful
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories found")
        Exit
    EndIf

    While 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop

        If $avArray[0] = "" Then
            $avArray[0] = $file
        Else
            _ArrayAdd($avArray, $file)

        EndIf
    WEnd
    ;_ArrayDisplay($avArray)

    FileClose($search)

    $OkButton = GUICtrlCreateButton("OK", 512, 408, 81, 25, $WS_GROUP)

    $Min = 0
    $Max = UBound($avArray)

    While 1
        $Random = Random($Min, $Max, 1)
        If $avArray[$Random] <> "" Then
            $Combo1 = GUICtrlCreateCombo($avArray[$Random], 152, 168, 129, 19)
            GUICtrlSetState($Combo1, $GUI_DISABLE)
            ExitLoop
        EndIf
    WEnd


    If $NumberOfadsToRun < 2 Then
        $Combo2 = GUICtrlCreateCombo("", 152, 218, 129, 19)
    Else
        While 1
            $Random = Random($Min, $Max, 1)
            Select
                Case $avArray[$Random] = GUICtrlRead($Combo1)
                Case Else
                    $Combo2 = GUICtrlCreateCombo($avArray[$Random], 152, 218, 129, 19)
                    GUICtrlSetState($Combo2, $GUI_DISABLE)
                    ExitLoop
            EndSelect
        WEnd

    EndIf

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = $GUI_EVENT_CLOSE
                Exit
            Case $nMsg = $OkButton
        EndSelect
    WEnd
EndFunc   ;==>RandomlyPickAd

The error I get:

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

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.