Jump to content

Why am I getting this Array error?


Recommended Posts

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.:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...