Jump to content

ArrayMinIndex (Please Help)


Recommended Posts

Hello! First, thanks for taking the time to help me out. I'd like to tell you how much autoit has helped me out with redundant chores on my computer. Unfortunately, I ran into a slight issue using _ArrayMinIndex. My entire program is about 700 lines long so I won't bore you with all the details, but basically, I have the program look at a set of downloads (Indicated by blue bars) and calculate the percentage of completion. After which, it returns the lowest value to me. That's all well and good, and the pixelsearches in the following function work great. However, when I add the

If @error = 0 Then

$download_array[$i] = 100 ; percentage that is...

It fails. I do not understand why. (I put 100 percent so that it will not be the min, even if the download doesn't really exist).

Without further delay, here is my function:

Func dl_findlowest()
    PixelSearch($download_pos[$i][0] + 1, $download_pos[$i][1] + 1, $download_pos[$i][0] + 2, $download_pos[$i][1] + 2, 0xFFFFFF, 40)
    If @error = 1 Then
        PixelSearch($download_pos[$i][0] + 0, $download_pos[$i][1] + 1, $download_pos[$i][0] + 2, $download_pos[$i][3] + 25, 0x051275, 20)
        If Not @error Then
            $download_pixel = PixelSearch($download_pos[$i][0] + 1, $download_pos[$i][1] + 1, $download_pos[$i][2] - 1, $download_pos[$i][1] + 2, 0xFFFFFF, 40)
            If Not @error Then
                $download_perc =100-(($download_pixel[0]-($download_pos[$i][2]-1))/(($download_pos[$i][0]+1)-($download_pos[$i][2]-1)))*100
                If $download_perc = 0 Then
                    $download_perc = 100
                EndIf
                $download_array[$i] = $download_perc
            EndIf
        EndIf

    ElseIf @error = 0 Then
        $download_array[$i] = 100 ;<<======= this causes issues
    EndIf



    If $i = $NumOfDownloads Then
        $z_pass1 = ((_ArrayMinIndex($download_array, 1, 0, $NumOfDownloads))-1); the -1 because, for some reason, they add 1 to the index (0 = 1)
        ToolTip("ArrayMinIndex : " & $z_pass1, 500, 500)
        If $z_pass1 >= 0 Then
            $z_pass2 = $download_array[$z_pass1]
            MsgBox(0,"Downloads", "Lowest percentage is: " & $z_pass2)
        EndIf
    EndIf

EndFunc
Edited by Neno
Link to comment
Share on other sites

  • Moderators

Neno,

Welcome to the AutoIt forum. :idea:

It fails

How?

Does the script stop completely with an error? If so, what error are you getting? Look in the bottom pane of SciTE to find out.

Or is it an internal function error? If so , how dioes it manifest itself?

What statements are you using to declare the $download_pos and $download_array arrays?

Sorry for all the questions, but there is not a lot to go on at the moment. :)

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

Ehhhhhhhhhhhh..... After I posted that (In frustration) I looked at it and looked at it, then I finally realized what an idiot I really was.

Initial testing with autoit's _ArrayMinIndex led me to believe that it was in fact starting at 1 rather than 0, so I was subtracting 1, then throwing it into another array as a subscript variable, causing a crash... *sigh* and that kept me stumped for 8 hours, because egotistically I guess I thought "I couldn't be wrong, it must be the programming language!"

I'm going to go jump off a bridge now, yeah.

Thanks for the response.

Neno,

Welcome to the AutoIt forum. :idea:

How?

Does the script stop completely with an error? If so, what error are you getting? Look in the bottom pane of SciTE to find out.

Or is it an internal function error? If so , how dioes it manifest itself?

What statements are you using to declare the $download_pos and $download_array arrays?

Sorry for all the questions, but there is not a lot to go on at the moment. :)

M23

Link to comment
Share on other sites

  • Moderators

Neno,

Glad you got it sorted. :idea:

By the way, when you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :)

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

Well, here was/is my main issue with autoit's _ArrayMinIndex function: If the array is not yet full (Meaning there are void entries in some of the array), the function returns an index for that void entry, rather than an error. Perhaps this is something the developers would like to add to the function as an error return. Here is the code change I made to Array.au3

; Search
    If $iCompNumeric Then
        For $i = $iStart To $iEnd
            If $avArray[$i] = Chr(0) Then Return SetError(4, 0, -1)
            If Number($avArray[$iMinIndex]) > Number($avArray[$i]) Then $iMinIndex = $i
        Next
    Else
        For $i = $iStart To $iEnd
            If $avArray[$i] = Chr(0) Then Return SetError(4, 0, -1)
            If $avArray[$iMinIndex] > $avArray[$i] Then $iMinIndex = $i
        Next
    EndIf
Link to comment
Share on other sites

  • Moderators

Neno,

There is no need to alter the UDF - just use the $iStart and $iEnd parameters to limit the elements involved. :idea:

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

Neno,

There is no need to alter the UDF - just use the $iStart and $iEnd parameters to limit the elements involved. :idea:

M23

Not a valid solution if there are void entries within the array, not out of bounds.

Edit: I threw my solution up on the bugtracker - Ehhh, If they deem it worthy fine, but I could see reasons for intentionally leaving it out.

Edited by Neno
Link to comment
Share on other sites

  • Moderators

Neno,

Not a valid solution if there are void entries within the array

A perfectly valid solution if you count the actual entries in the array, or only expand your array to fit the number of actual entries.

As we often say, AutoIt cannot read your mind, you have to tell it what you want it to do. :idea:

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

Neno,

A perfectly valid solution if you count the actual entries in the array, or only expand your array to fit the number of actual entries.

As we often say, AutoIt cannot read your mind, you have to tell it what you want it to do. :idea:

M23

Blame it on Valik. he hasn't done a damn thing with the DoMyThinkingForMe() function yet.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Yeah, no... I get what it is you're saying, but here's the dynamic of things:

I have a variable $i, that is a global variable. This variable runs the main program loop, it also gets used as the index for the array I'm using in the first post. The problem is that even though I tell the array to If $i = $NumOfDownloads- (wait until it's gone around once before finding the min) It doesn't. I do not know why is doesn't, sequentially and logically it makes sense, but... It doesn't.

I needed to throw the error because it is a valid bound most of the time.

Hopefully that's clearer.

EDIT:::

New code would read as follows>>

Func dl_findlowest()
    ;;;;<===== START SOME PSEUDO CODE ======>;;;; 
    If -some perimeter- Then
        $download_array[$i] = -some var- 
    ;;;;<===== END   SOME PSEUDO CODE ======>;;;;


    ElseIf @error = 0 Then
        $download_array[$i] = 100
    EndIf


    $z_pass1 = (_ArrayMinIndex($download_array, 1, 0, $NumOfDownloads))
    If Not @error Then
        $z_pass2 = $download_array[$z_pass1]
        MsgBox(0,"Downloads", "Lowest percentage is: " & $z_pass2)
    EndIf

EndFunc

(with my udf change)

Rather than:

If $i = $NumOfDownloads Then
        $z_pass1 = (_ArrayMinIndex($download_array, 1, 0, $NumOfDownloads))
        If $z_pass1 >= 0 Then
            $z_pass2 = $download_array[$z_pass1]
            MsgBox(0,"Downloads", "Lowest percentage is: " & $z_pass2)
        EndIf
    EndIf

As you can see they should both work equally, but, the latter does not work -all- the time.

Edited by Neno
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...