Jump to content

Array walking


Phaser
 Share

Recommended Posts

Hi everyone

Just out of interest (although I may use it) what is the best way in Autoit to do the following

Local $array [10] = [1,2,3,4,5,6,7,8,9,10]

If $step = -1 Then; value returned when target reached via ArraySearch

If $stepcount = 0 Then
$progress = $array[0]; returns 1
ElseIf $stepcount > 0 Then
$progress = $array[] +1 ;get next value
EndIf

At this line $progress = $array[]+1 I would just like it to go to the next array value each time, 1 then 2 then 3 then 4 etc until $step is no longer true, can't get my head around it and the help file is a bit vague

Link to comment
Share on other sites

Hi everyone

Just out of interest (although I may use it) what is the best way in Autoit to do the following

Local $array [10] = [1,2,3,4,5,6,7,8,9,10]

If $step = -1 Then; value returned when target reached via ArraySearch

If $stepcount = 0 Then
$progress = $array[0]; returns 1
ElseIf $stepcount > 0 Then
$progress = $array[] +1 ;get next value
EndIf

At this line $progress = $array[]+1 I would just like it to go to the next array value each time, 1 then 2 then 3 then 4 etc until $step is no longer true, can't get my head around it and the help file is a bit vague

$progress = $array[]+1

=

$progress = $progress+1

Link to comment
Share on other sites

  • Moderators

Phser,

Sorry, but for the life of me I cannot completely understand what you are trying to do here.

If $step = -1 Then; value returned when target reached via ArraySearch

What target? Reached how? _ArraySearch can move through the array in either direction depending on the $iForward parameter.

If I have understood the second part correctly, you just need a For...Next loop:

Local $aArray [10] = [1,2,3,4,5,6,7,8,9,10]

; get STEPCOUNT value
While 1 ; Infinite loop
    $iInput = InputBox("Step", "Enter your required STEPCOUNT value", "A number from 0 to 9")
    ; Errorcheck the input value
    If $iInput = "" Then Exit ; Cancel pressed
    $iStepCount = Int($iInput) ; Convert to integer
    If $iStepCount < 0 Or $iStepCount > 9 Then ; Check range
        MsgBox(0, "Error", "Invalid STEPCOUNT!")
    Else
        ExitLoop ; Exit While..WEnd loop to next section
    EndIf
WEnd

; Run through the elements from 0 to STEPCOUNT
For $i = 0 To $iStepCount - 1
    $iProgress = $aArray[$i]
    ConsoleWrite($iProgress & @CRLF)
Next

Is this close? If not, could you please explain what you are trying to do a little more clearly! :D

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

Yeah I know, I am cr@p at explaining things.

I think M23 has produced something I "think" is what I want

For $i = 0 To $iStepCount - 1
    $iProgress = $aArray[$i]
    ConsoleWrite($iProgress & @CRLF)
Next

Will see if I can adapt it to my needs

My initial post simplified (hopefully) my last thread was to create a 2D array with 6 values, now using ArraySearch to look into that array to see if a specific item has not been entered for x amounts of time I get a prompt (msgbox) and a number from the progress array should be returned, after the first msgbox prompt the first element [0] is returned, now if the next set of data does not contain the searched for value the msgbox comes up again but with the next progress array value [1] if the next data set still doesnt contain the searched for value then the next progress array value appears on the msgbox [2] and if at anytime the value does appear the array will display the [0] as default

At the moment I am using $progress = $progress+1 but that limits me to set values, I would like to be able to set the array to what I need, for example

Local $array[5] = [1,4,7,11,26]

These won't be possible using maths so I thought of putting those in an array and walking through them if a value is still false

Does that make any sense?

Link to comment
Share on other sites

  • Moderators

Phaser,

I have used the code we developed in your other thread to produce this:

; include
#include <GUIConstantsEx.au3>
#include <Array.au3>

; declarations

Global $iMax_Elements = 10 ; just for testing - you can set what you want

Global $aArray[$iMax_Elements][6] ; the array is now a fixed size
Global $thenumber, $colour, $shape, $sides, $coating, $size

Global $aSearch_Array[5] = [11,13,15,17,19]  ; <<<<<<<<<<<<<<<< your search terms


; hotkey
HotKeySet("{ESC}", "getoutofhere")

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

; GUI
$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "getoutofhere")

$hButton_Add = GUICtrlCreateButton("Fill Array", 10, 10, 80, 30)
GUICtrlSetOnEvent($hButton_Add, "goforit")

$hButton_Search = GUICtrlCreateButton("Search in Array", 10, 50, 80, 30)
GUICtrlSetOnEvent($hButton_Search, "looking")

GUISetState()

; idle loop
While 1
    Sleep(10)
WEnd

Func looking()

    For $i = 0 To UBound($aSearch_Array) - 1 ; For each search array term in order
        $iIndex = _ArraySearch($aArray, $aSearch_Array[$i]) ; Look in the main array (first column) to see if search term is there
        If $iIndex = -1 Then ; Search failed
            MsgBox(0, "Search Failed", $aSearch_Array[$i] & " was not found")
        Else
            MsgBox(0, "Search Success", $aSearch_Array[$i] & " was found!")
            Return ; comment this out if you want to see if other search elements were also present
        EndIf
    Next

EndFunc

Func goforit()

    ; Do this 10 times to fill the array
    For $i = 1 To 10

        ; Simulate getting the data from the other app and using getnumberdetails() to get it into the right variables
        $thenumber = Random(10, 20, 1)
        $colour = Random(10, 99, 1)
        $shape = Random(10, 99, 1)
        $sides = Random(10, 99, 1)
        $coating = Random(10, 99, 1)
        $size = Random(10, 99, 1)

        sendtoarray()

    Next

    ; Display the array we are searching so we can see if the search items exist to check the code!!!!!
     _ArrayDisplay($aArray)


EndFunc

Func sendtoarray()

    ; Move everything down one row
    For $i = $iMax_Elements - 2 To 0 Step -1
        For $j = 0 To 5
            $aArray[$i + 1][$j] = $aArray[$i][$j]
        Next
    Next

    ; Now put the new data into the first row
    $aArray[0][0] = $thenumber
    $aArray[0][1] = $colour
    $aArray[0][2] = $shape
    $aArray[0][3] = $sides
    $aArray[0][4] = $coating
    $aArray[0][5] = $size

EndFunc

Func getoutofhere()
    Exit
EndFunc

Press "Fill" and you see the array so you can note which of the search terms are present (I have limited the array to 10-20 and the search terms are the odd numbers). Press "Search" and you get MsgBoxs if the search terms are present.

Are we getting warm?

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

Thanks for yuor efforts guys, I have it sorted now from my original code

If $stepcount = 0 Then
$progress = $array[$stepcount]; returns 1
ElseIf $stepcount > 0 Then
$progress = $array[$stepcount] ;get next value
$stepcount = $stepcount+1
EndIf

By using the $stepcount value which is already the correct value and it resets itself at the end so thats perfect. Thanks again

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