Mobilfan Posted September 22, 2018 Share Posted September 22, 2018 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 More sharing options...
Subz Posted September 22, 2018 Share Posted September 22, 2018 Your error is lines 23 and 24, remove Local, also why not just use _ArraySort function? Link to comment Share on other sites More sharing options...
Mobilfan Posted September 23, 2018 Author Share Posted September 23, 2018 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 More sharing options...
Moderators Melba23 Posted September 23, 2018 Moderators Share Posted September 23, 2018 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: expandcollapse popup#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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mobilfan Posted September 23, 2018 Author Share Posted September 23, 2018 Thanks this solved it. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now