Guest Posted August 24, 2011 Posted August 24, 2011 Oops I had a basic mistake in planning ... I need the code will select the lowest number but not lowest than another number Which is updated every second...... Thanks
Guest Posted August 25, 2011 Posted August 25, 2011 (edited) Help me! Edit: dont help me ... I want to do it myself Edited August 25, 2011 by Guest
Guest Posted August 26, 2011 Posted August 26, 2011 (edited) Ok I have now this: #include <file.au3> #include <Array.au3> Global $i_lowest $time = @HOUR & @MIN & @SEC Dim $a_secondfile _FileReadToArray("code.txt", $a_secondfile) _ArrayAdd($a_secondfile, $time) _ArraySort($a_secondfile) $iIndex = _ArraySearch($a_secondfile, $time, 0, 0, 0, 1) While 1 $i_lowest = _ArrayMin($a_secondfile, 1, 1) _ArrayDisplay($a_secondfile, "$avArray AFTER _ArraySort() ascending" ) If $i_lowest < $a_secondfile[$iIndex] Then _ArrayDelete($a_secondfile, 0) EndIf WEnd The idea is that the code will delete the number was lower than the number $ a_secondfile [$ iIndex]. But having other numbers that are lower than $ a_secondfile [$ iIndex] so the code does not delete them. He just deletes only once ... Why? It's in the Loop ... I do not understand. Help me! Edited August 26, 2011 by Guest
bogQ Posted August 26, 2011 Posted August 26, 2011 what data do you have in code.txt? TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
Guest Posted August 26, 2011 Posted August 26, 2011 what data do you have in code.txt? Several rows of numbers that Smaller than the number of the time( $time = @HOUR & @MIN & @SEC ) This code: #include <file.au3> #include <Array.au3> Global $i_lowest Dim $a_secondfile _FileReadToArray("code.txt", $a_secondfile) While 1 $time = @HOUR & @MIN & @SEC _ArrayAdd($a_secondfile, $time) _ArraySort($a_secondfile) $iIndex = _ArraySearch($a_secondfile, $time, 0, 0, 0, 1) $i_lowest = _ArrayMin($a_secondfile, 1, 1) _ArrayDisplay($a_secondfile, "$avArray AFTER _ArraySort() ascending" ) If $i_lowest < $a_secondfile[$iIndex] Then _ArrayDelete($a_secondfile, 0) EndIf WEnd Do it but he adds a couple of times the number of time
bogQ Posted August 26, 2011 Posted August 26, 2011 (edited) #include <file.au3> #include <Array.au3> Global $time = @HOUR & @MIN & @SEC, $a_secondfile _FileReadToArray("code.txt", $a_secondfile) _ArrayDelete($a_secondfile, 0) _ArrayAdd($a_secondfile, $time) _ArraySort($a_secondfile) $iIndex = _ArraySearch($a_secondfile, $time, 0, 0, 0, -1) _ArrayDisplay($a_secondfile, $time ) For $x = UBound($a_secondfile)-1 To 0 Step -1 If Number($a_secondfile[$x]) < Number($time) Then _ArrayDelete($a_secondfile, $x) _ArrayDisplay($a_secondfile, $time ) EndIf Next MsgBox(0,"","the end") _ArrayDisplay($a_secondfile, "the end" ) i think that number() done the trick Edited August 26, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
Guest Posted August 26, 2011 Posted August 26, 2011 (edited) Thank you. It works but I did not understand how it works .. What does it mean this line: For $x = UBound($a_secondfile)-1 To 0 Step -1 ? Edited August 26, 2011 by Guest
bogQ Posted August 26, 2011 Posted August 26, 2011 (edited) UBound returns how many elements there are in array so we will set $x (temp variable) to hold number of array rows, the array start from 0 so we lower will UBound witn -1 so $x will hold the correct loop number starting from 0 element in array from $x to 0 (from number of rows in array to 0 row) step -1, so that itl count down and not up (count up is the defold in 'For' loop) Edited August 26, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
smartee Posted August 26, 2011 Posted August 26, 2011 hi, bogQ already covered it, but I already typed this bit so another explanation won't hurt right? That line iterates through the entire array in reverse order. UBound returns the size of the array so if I have three elements in array $asFruits like$asFruits[0] = Mango $asFruits[1] = Pineapple $asFruits[2] = Strawberry Then UBound($asFruits) will return a value of 3. However, to get the last element, $asFruits[uBound($asFruits)] is invalid since the last element is given by $asFruits[2] or $asFruits[3-1] or $asFruits[uBound($asFruits)-1] The For loop is one of the many available loop structures available in AutoIt and it looks like this For..To..Step.. ..(body) Next So in words, For $x = UBound($a_secondfile)-1 To 0 Step -1 would mean: Assign each index of this array to $x, starting at the highest index(UBound($a_secondfile)-1) then stepping down 1 (Step -1) at a time until the 0th position. Of course the Step -1 action is only performed after the body of the loop is executed and the matching Next keyword is encountered. Hope this helps, -smartee
Guest Posted August 26, 2011 Posted August 26, 2011 (edited) OKThe code.txt now contains this:1=201108824031212 1=201108824051215 1=201108824041242So I added:For $x = 1 To $a_secondfile[0] $a_secondfile[$x] = StringTrimLeft($a_secondfile[$x], 11) NextBut it does not work ..Why?This complete code:expandcollapse popup#include <file.au3> #include <Array.au3> Global $a_secondfile _FileReadToArray("code.txt", $a_secondfile) For $x = 1 To $a_secondfile[0] $a_secondfile[$x] = StringTrimLeft($a_secondfile[$x], 11) Next _ArrayDelete($a_secondfile, 0) _ArrayAdd($a_secondfile, @HOUR & @MIN & @SEC) While 1 $hour = @HOUR If $hour = "00" Then $hour = "24" EndIf If $hour = "01" Then $hour = "25" EndIf If $hour = "02" Then $hour = "26" EndIf If $hour = "03" Then $hour = "27" EndIf If $hour = "04" Then $hour = "28" EndIf If $hour = "05" Then $hour = "29" EndIf If $hour = "06" Then $hour = "30" EndIf If $hour = "07" Then $hour = "31" EndIf If $hour = "08" Then $hour = "32" EndIf If $hour = "09" Then $hour = "33" EndIf $time = $hour & @MIN & @SEC _ArraySort($a_secondfile) $iIndex = _ArraySearch($a_secondfile, $time, 0, 0, 0, -1) For $x = UBound($a_secondfile)-1 To 0 Step -1 If Number($a_secondfile[$x]) < Number($time) Then _ArrayDelete($a_secondfile, $x) EndIf Next _ArrayDisplay($a_secondfile, $time ) WEndEDIT:It works.Wrong test Edited August 26, 2011 by Guest
bogQ Posted August 26, 2011 Posted August 26, 2011 (edited) if it works nwm if you need something shorter than 'If Then'Select Case $hour = "00" $hour = "24" Case $hour = "01" $hour = "25" Case $hour = "02" $hour = "26" Case $hour = "03" $hour = "27" Case $hour = "04" $hour = "28" Case $hour = "05" $hour = "29" Case $hour = "06" $hour = "30" Case $hour = "07" $hour = "31" Case $hour = "08" $hour = "32" Case $hour = "09" $hour = "33" EndSelect Edited August 26, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
Guest Posted August 26, 2011 Posted August 26, 2011 (edited) Thank you. But are you sure that $time is updated every second? Edited August 26, 2011 by Guest
bogQ Posted August 26, 2011 Posted August 26, 2011 (edited) that depends of array size and of your comp speed, but if your not playing with alot of lines id say it update about minimum 500-1000 times in 1 second Edited August 26, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
smartee Posted August 26, 2011 Posted August 26, 2011 if you need something shorter than 'If Then'..But..but.. I like If..Then $hour = Number($hour) If ($hour >= 0) And ($hour <= 9) Then $hour += 24 EndIf
bogQ Posted August 26, 2011 Posted August 26, 2011 do it in 2 no need 4 4 TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.
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