Phaser Posted September 1, 2009 Posted September 1, 2009 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
WolfWorld Posted September 1, 2009 Posted September 1, 2009 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 Main project - Eat Spaghetti - Obfuscate and Optimize your script. The most advance add-on.Website more of GadGets!
jvanegmond Posted September 1, 2009 Posted September 1, 2009 You may want to write a script that doesn't crash on the third line of code to illustrate what you're trying. I may start to think you're looking for the best way to crash AutoIt.. Or something. github.com/jvanegmond
Moderators Melba23 Posted September 1, 2009 Moderators Posted September 1, 2009 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 ArraySearchWhat 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! 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
Phaser Posted September 1, 2009 Author Posted September 1, 2009 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?
Moderators Melba23 Posted September 1, 2009 Moderators Posted September 1, 2009 Phaser,I have used the code we developed in your other thread to produce this:expandcollapse popup; 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 EndFuncPress "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 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
Phaser Posted September 1, 2009 Author Posted September 1, 2009 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
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