Jump to content

"Subscript used on non-accessible variable" while defining variable from array


Mobilfan
 Share

Recommended Posts

So I wanted to make a script being able to sort the values in an array (from small to big) and I got the error: "Subscript used on non-accessible variable" If anyone could take a look on my code here you go:

#include <Array.au3>
#include <MsgBoxConstants.au3>
local $counter = 0
local $array[0]
local $progress = 0
local $number1 = 0
local $number2 = 0
while True
   _ArrayAdd ( $array, InputBox ( "Input number " & $counter, "Please enter value:" ) )
   local $temp = MsgBox ( 4, "Input", "Do you want to input another value?" )
   if $temp = 7 Then
      ExitLoop
   EndIf
   local $temp = $counter
   local $counter = Number ( $temp + 1 )
WEnd
while True
   _ArrayDisplay ( $array, "1D display" )
   //The next line is where the error occurs
   local $number1 = $array[$progress]
   local $number2 = $array[Number ( $progress + 1 )]
   if $number1 > $number2 Then
      local $array[$progress] = $number2
      local $array[Number ( $progress + 1 )] = $number1
   EndIf
   local $temp = $progress
   local $progress = Number ( $temp + 1 )
   if $progress > $counter Then
      local $progress = 0
   EndIf
WEnd

 

Link to comment
Share on other sites

Thanks this kinda solved my problem. The only problem now is that I get another error:

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
local $number2 = $array[Number ( $progress + 1 )]
local $number2 = ^ ERROR

Also why I am not using _ArraySort. I just wanted to see if it was possible for me to script something like this (it was not).

Link to comment
Share on other sites

  • Moderators

Mobilfan,

You are trying to access an element of the array which does not exist - look at the values that appear in the console when you run your code:

#include <Array.au3>
#include <MsgBoxConstants.au3>

$counter = 0
Local $array[0]
$progress = 0
$number1 = 0
$number2 = 0
While True
    _ArrayAdd($array, InputBox("Input number " & $counter, "Please enter value:"))
    $temp = MsgBox(4, "Input", "Do you want to input another value?")
    If $temp = 7 Then
        ExitLoop
    EndIf
    $temp = $counter
    $counter = Number($temp + 1)
WEnd

ConsoleWrite("Array size: " & UBound($array) & @CRLF)
ConsoleWrite("Starting loop" & @CRLF & @CRLF)

While True
    _ArrayDisplay($array, "1D display")

    ConsoleWrite("Index ($progress): " & $progress & @CRLF)

    $number1 = $array[$progress]

    ConsoleWrite("Index + 1 ($progress + 1): " & $progress + 1 & @CRLF & @CRLF)

    $number2 = $array[Number($progress + 1)]
    If $number1 > $number2 Then
        $array[$progress] = $number2
        $array[Number($progress + 1)] = $number1
    EndIf
    $temp = $progress
    $progress = Number($temp + 1)
    If $progress > $counter Then
        $progress = 0
    EndIf
WEnd

Remember that AutoIt arrays start at element 0 - not 1 - so the highest index is always 1 less that the size of the array.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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