Jump to content

_ArraySort Errors


Recommended Posts

This was the first time i've tried to use the array functions, and i'm getting errors that i don't understand. This is what i get with _ArraySort. i get errors with _ArrayDisplay too.

My array is a two dimensional.

Line 0 (File "\\daladm01\oa\Drivers\Install Drivers.exe"):

If $a_Array[$Count] > $a_Array[$Count + $Gap] Then

If ^ ERROR

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

Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Link to comment
Share on other sites

You'll need to post the script for the 1 error.

_ArrayDisplay

--------------------------------------------------------------------------------

Displays a 1-dimensional array in a message box.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Many array problems are that a 10 element array starts at 0.

$a_array[0]

$a_array[1]

$a_array[2]

$a_array[3]

$a_array[4]

$a_array[5]

$a_array[6]

$a_array[7]

$a_array[8]

$a_array[9] ; 10th element

so be careful when using things like $a_array[$count]

if your script ever hits $count=10 or:

in the case of $a_Array[$Count + $Gap]

$Count + $Gap=10, you will error out in a 10 element array.

I would imagine that you are doing a test like:

Dim $a_array[10]
$a_array[0]=12
$a_array[1]=14
$a_array[2]=16
$a_array[3]=18
$a_array[4]=19
$a_array[5]=123
$a_array[6]=124
$a_array[7]=125
$a_array[8]=126
$a_array[9]=128
$gap=1
for $count=0 to 9
 If $a_Array[$Count] > $a_Array[$Count + $Gap] Then 
msgbox(1,"ha!","")
endif
next

This code will crash just as easy as if you forget to assign an array variable in the _ArraySort() function like using:

_ArraySort($myarray)

instead of :

$sortedarray=_ArraySort($myarray)

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

hmm, i'm not sure where the confusion is, but i'm trying to use the User Defined functions for manipulating arrays that i downloaded from this site.

The one i'm trying to use is _ArraySort, and I've also tried _ArrayDisplay. Both generate errors.

My script is very long, but here is where i'm trying to use it:

Func ListDrivers()
    
    Dim $iDriverNum
;MsgBox(0, "test", "test")
    GUICtrlDelete($cboDriverList)
    
    If GUICtrlRead($cboMachines) = "Select the machine" Then
        
        Return
        
    EndIf
    
    WriteLog(GUICtrlRead($cboMachines) & ' selected.')
    $cboDriverList = GUICtrlCreateCombo("All", 210, 10, 200)
    $sDrivers = IniReadSection("Install Drivers.ini", GUICtrlRead($cboMachines))
    
    _ArraySort($sDrivers)
        
    For $iDriverNum = 1 to $sDrivers[0][0]
        
        GUICtrlSetData($cboDriverList, $sDrivers[$iDriverNum][0])
        
    Next
    
EndFunc
Edited by laurin1

Keith Davis

MCSA, ZCE, A+, N+

http://www.laurinkeithdavis.com

Link to comment
Share on other sites

  • Developers

hmm, i'm not sure where the confusion is, but i'm trying to use the User Defined functions for manipulating arrays that i downloaded from this site.

<{POST_SNAPBACK}>

#include <Array.au3>

_ArraySort ( ByRef $a_Array, [[[[[$i_Descending], $i_Base=0], $i_Ubound=0], $i_Dim=1], $i_SortIndex=0] )

Parameters

$a_Array Input Array to be sorted.

$i_Descending Optional: 1=Sort Descending else Ascending.

$i_Base Optional: Start Array index for sort, normally set to 0 or 1.

$i_Ubound Optional: Set the UBound for sorting which will only sort the defined number of entries in stead of the whole array.

$i_Dim Optional: Number of occurrences in the second dimension

eg $A[100] = 0, $A[100][2] = 2, $A[100][5] = 5

$i_SortIndex Optional: The index to Sort on.

You will have to tell _ArraySort that you want to sort an 2 dimensional array.... something like:

_ArraySort($sDrivers,0,0,0,2)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

_ArrayDisplay() does not work on 2-d arrays.

use instead my _ArrayBox() function for 2d arrays:

http://www.autoitscript.com/forum/index.php?showtopic=12720

or my _ArrayNMap() function for multi-dimensional or nested arrays:

http://www.autoitscript.com/forum/index.ph...t=0&p=90303

Link to comment
Share on other sites

  • Developers

When I do that, the function removes all the data from my array.

<{POST_SNAPBACK}>

Dunno what your problem is you are having but let me give you an example of how this works..

This is a 2 dimension array which is first displayed then sorted on the first dimension, displayed and then sorted on the second dimension which is the original order:

#include <Array.au3>
Dim $avArray[10][2]
$avArray[0][0] = "JPM"
$avArray[1][0] = "Holger"
$avArray[2][0] = "Jon"
$avArray[3][0] = "Larry"
$avArray[4][0] = "Jeremy"
$avArray[5][0] = "Valik"
$avArray[6][0] = "Cyberslug"
$avArray[7][0] = "Nutster"
$avArray[8][0] = "Tylo"
$avArray[9][0] = "JdeB"
For $x = 0 to UBound($avArray) -1 
    $avArray[$x][1] = $x
Next
ConsoleWrite("**** Unsorted"& @LF)
_ArrayDisplayMult($avArray)
_ArraySort( $avArray,0,0,0,2,0)
ConsoleWrite(@LF & @LF & "**** sorted dim 1"& @LF)
_ArrayDisplayMult($avArray)
_ArraySort( $avArray,0,0,0,2,1)
ConsoleWrite(@LF & @LF & "**** sorted dim 2" & @LF)
_ArrayDisplayMult($avArray)

Func _ArrayDisplayMult($aivArray)
    For $x = 0 to UBound($aivArray) -1 
        ConsoleWrite($aivArray[$x][0] & @lf)
    Next
EndFunc

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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