Hest Posted April 20, 2009 Share Posted April 20, 2009 (edited) I have a little problem and I'm stuck now. I have an array with a bunch of numbers 1, 10, 12, 20, 40, 48, 54... and so on. It can be any number. Im my program, the user can calculate a number and now I need to find the number in the array that is bigger and closest to it. So, if array = 1, 10, 12, 20, 40, 48, 54 and the user result is 14, I need the output to be 20. Can anyone explain how I can do that?. I thought about a while loop and just checking the user result and then +1 untill I get a hit, but I dont think thats the best way to do it. Edited April 20, 2009 by Hest Software:Model Train Calculator (Screen)Autoit3 beginner! Link to comment Share on other sites More sharing options...
Danny35d Posted April 20, 2009 Share Posted April 20, 2009 Dim $aNumbers[7] = [1, 10, 12, 20, 40, 48, 54] $iUserNumber = InputBox('Comparing Numbers', 'Enter a number between 1 an 54') $iBiggerNumber = 0 For $iNumber In $aNumbers If $iBiggerNumber < $iUserNumber And $iNumber > $iUserNumber Then $iBiggerNumber = $iNumber Next MsgBox(0, 'Comparing Numbers', 'The bigger and closest number to ' & $iUserNumber & ' is ' & $iBiggerNumber & '.') AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Hest Posted April 20, 2009 Author Share Posted April 20, 2009 (edited) Thx alot Danny, it's working now.Made a little change to it, because it jumped a number, if the users number was in the array. Was missing a =If $iBiggerNumber < $iUserNumber And $iNumber >= $iUserNumber Then $iBiggerNumber = $iNumber Edited April 20, 2009 by Hest Software:Model Train Calculator (Screen)Autoit3 beginner! Link to comment Share on other sites More sharing options...
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