SteelSeries

Converting a snippet of AutoIT to C++

8 posts in this topic

#1 ·  Posted (edited)

Hi, 
 
Hopefully someone here will be able to help but I need a hand in converting this AutoIT piece of code or at least help me understand what's happening.
 
 
I am trying to convert that snippet of code there for one of my C++ projects and as you can see in the above link I have tried to comment it with what I understand is happening but I am a little lost.
For example where is the the iend and istart coming from? Are they just integer variables of the start of the array ( 0? ) and the end of the array? (could be 54 for example) ?
 
Any help is appreciated!
 
Thanks.
Edited by SteelSeries

Share this post


Link to post
Share on other sites



SteelSeries,

Welcome to the AutoIt forums. :)

That looks like a hacked version of the _Array_MinIndex function in Array.au3 modified to work on 1D arrays only. The code works as follows: :)

Func Mystery($dis, ByRef $minf, $iStart, $iend)                                     ; pass and array, a var to hold the min index, and the start and end elements to search

    $avarray = $dis                                                                     ; Copy the passed array to a local array
    If Not IsArray($avarray) Then Return $minf = ""                                 ; If it is not a array then return and var holds an empty string
    If UBound($avarray, 0) <> 1 Then Return $minf = ""                                  ; If the passed array is not 1D then return and var holds an empty string
    Local $iubound = UBound($avarray) + -1                                              ; Get the index of the top element of the array
    If $iend < 1 Or $iend > $iubound Then $iend = $iubound                              ; If passed end index is out of bounds or 0, set to end
    If $iStart < 0 Then $iStart = 0                                                 ; If passed start index is < 0 then set to 0
    If $iStart > $iend Then Return $minf = ""                                           ; If start > end then return an empty string
    Local $iminindex = $iStart                                                          ; Assume index of lowest element is the start index
    Local $ichecknum = 0                                                                ; Create a flag (cleared)
    For $i = $iStart To $iend                                                           ; Loop through the elements from start to end indices
        If Not IsNumber($avarray[$i]) Then ContinueLoop                             ; If element is not a number then ignore
        If Not $ichecknum Then $iminindex = $i                                          ; If flag not set then set min index to this element index
        $ichecknum = 1                                                                  ; Set flag to show at least one number has been found
        If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminindex = $i ; If current min index element > this element, set this element as min
    Next
    $minf = $iminindex                                                                  ; Set var to the current min index

EndFunc   ;==>Mystery
But I cannot help with the C++ part, sorry. :(>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

SteelSeries,

Welcome to the AutoIt forums. :)

That looks like a hacked version of the _Array_MinIndex function in Array.au3 modified to work on 1D arrays only. The code works as follows: :)

Func Mystery($dis, ByRef $minf, $iStart, $iend)                                     ; pass and array, a var to hold the min index, and the start and end elements to search

    $avarray = $dis                                                                     ; Copy the passed array to a local array
    If Not IsArray($avarray) Then Return $minf = ""                                 ; If it is not a array then return and var holds an empty string
    If UBound($avarray, 0) <> 1 Then Return $minf = ""                                  ; If the passed array is not 1D then return and var holds an empty string
    Local $iubound = UBound($avarray) + -1                                              ; Get the index of the top element of the array
    If $iend < 1 Or $iend > $iubound Then $iend = $iubound                              ; If passed end index is out of bounds or 0, set to end
    If $iStart < 0 Then $iStart = 0                                                 ; If passed start index is < 0 then set to 0
    If $iStart > $iend Then Return $minf = ""                                           ; If start > end then return an empty string
    Local $iminindex = $iStart                                                          ; Assume index of lowest element is the start index
    Local $ichecknum = 0                                                                ; Create a flag (cleared)
    For $i = $iStart To $iend                                                           ; Loop through the elements from start to end indices
        If Not IsNumber($avarray[$i]) Then ContinueLoop                             ; If element is not a number then ignore
        If Not $ichecknum Then $iminindex = $i                                          ; If flag not set then set min index to this element index
        $ichecknum = 1                                                                  ; Set flag to show at least one number has been found
        If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminindex = $i ; If current min index element > this element, set this element as min
    Next
    $minf = $iminindex                                                                  ; Set var to the current min index

EndFunc   ;==>Mystery
But I cannot help with the C++ part, sorry. :(>

M23

 

 

Amazing, thank you very much. I should be able to piece together what I need now. ;)

Share this post


Link to post
Share on other sites

SteelSeries,

Glad I could help. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

SteelSeries,

Glad I could help. :)

M23

Sorry to bump this thread back into life, but I have another question :D Could this function be used for some kind of getting the smallest number in the array/getting the index of the lowest number?

Edited by SteelSeries

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

SteelSeries,

It would need to be modified but the principle is exactly the same. This should do it: :)

Func Mystery($dis, ByRef $minf, $iStart, $iend)                                     ; pass and array, a var to hold the min value, and the start and end elements to search

    $avarray = $dis                                                                     ; Copy the passed array to a local array
    If Not IsArray($avarray) Then Return $minf = ""                                 ; If it is not a array then return and var holds an empty string
    If UBound($avarray, 0) <> 1 Then Return $minf = ""                                  ; If the passed array is not 1D then return and var holds an empty string
    Local $iubound = UBound($avarray) + -1                                              ; Get the index of the top element of the array
    If $iend < 1 Or $iend > $iubound Then $iend = $iubound                              ; If passed end index is out of bounds or 0, set to end
    If $iStart < 0 Then $iStart = 0                                                 ; If passed start index is < 0 then set to 0
    If $iStart > $iend Then Return $minf = ""                                           ; If start > end then return an empty string
    Local $iminvalue = $iStart                                                          ; Assume min value is value of the start index
    Local $ichecknum = 0                                                                ; Create a flag (cleared)
    For $i = $iStart To $iend                                                           ; Loop through the elements from start to end indices
        If Not IsNumber($avarray[$i]) Then ContinueLoop                             ; If element is not a number then ignore
        If Not $ichecknum Then $iminindex = $avarray[$i]                                ; If flag not set then set min value to this element value
        $ichecknum = 1                                                                  ; Set flag to show at least one number has been found
        If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminvalue = $avarray[$i] ; If current min value > this value, set this value as min
    Next
    $minf = $iminvalue                                                                  ; Set var to the current min value

EndFunc   ;==>Mystery
M23

Edit: Just seen your edit. The original code gave you the index of the lowest number - the above gives you the value itself. Look in the Help file at _ArrayMin & _ArrayMinIndex to see the difference. ;)

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

SteelSeries,

It would need to be modified but the principle is exactly the same. This should do it: :)

Func Mystery($dis, ByRef $minf, $iStart, $iend)                                     ; pass and array, a var to hold the min value, and the start and end elements to search

    $avarray = $dis                                                                     ; Copy the passed array to a local array
    If Not IsArray($avarray) Then Return $minf = ""                                 ; If it is not a array then return and var holds an empty string
    If UBound($avarray, 0) <> 1 Then Return $minf = ""                                  ; If the passed array is not 1D then return and var holds an empty string
    Local $iubound = UBound($avarray) + -1                                              ; Get the index of the top element of the array
    If $iend < 1 Or $iend > $iubound Then $iend = $iubound                              ; If passed end index is out of bounds or 0, set to end
    If $iStart < 0 Then $iStart = 0                                                 ; If passed start index is < 0 then set to 0
    If $iStart > $iend Then Return $minf = ""                                           ; If start > end then return an empty string
    Local $iminvalue = $iStart                                                          ; Assume min value is value of the start index
    Local $ichecknum = 0                                                                ; Create a flag (cleared)
    For $i = $iStart To $iend                                                           ; Loop through the elements from start to end indices
        If Not IsNumber($avarray[$i]) Then ContinueLoop                             ; If element is not a number then ignore
        If Not $ichecknum Then $iminindex = $avarray[$i]                                ; If flag not set then set min value to this element value
        $ichecknum = 1                                                                  ; Set flag to show at least one number has been found
        If Number($avarray[$iminindex]) > Number($avarray[$i]) Then $iminvalue = $avarray[$i] ; If current min value > this value, set this value as min
    Next
    $minf = $iminvalue                                                                  ; Set var to the current min value

EndFunc   ;==>Mystery
M23

Edit: Just seen your edit. The original code gave you the index of the lowest number - the above gives you the value itself. Look in the Help file at _ArrayMin & _ArrayMinIndex to see the difference. ;)

 

Ah, brilliant! Thanks again, turns out that is exactly what it is; just a func to find the lowest number and its index.

Share this post


Link to post
Share on other sites

SteelSeries,

Again - glad I could help. :)

But when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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