Maze573 Posted January 6, 2015 Share Posted January 6, 2015 First of all, I'm pretty new to programming with AutoIt so please be patient. And second: Yes I searched the forum and the documentation for similar topics, but I did not find anything relevant (I'm not an native english speaker so maybe I searched the wrong phrases and I would be glad if you teach me wrong and there is a special function). For a school- (math-)project I am working on a program, which sends randomized numbers to the project-program of my buddy, everything with the randomizing, sending and looping works fine already, but to be honest I have no idea how to program the last function: I want that every number only gets send once. Send(Random(1, 365, 1)) For example if the first random days are 67,89,345,192 I dont want them to be drawn again. So they have to be remembered somehow. I searched for a function that would be able to do that, but I did not find a specific one. So I'm afraid the solution is something that is far beyond my level. I would be glad if someone could help me with this tough nut! Best regards and greetings from Austria Maze573 Link to comment Share on other sites More sharing options...
JohnOne Posted January 6, 2015 Share Posted January 6, 2015 Get your numbers into an array. Loop through the array from end(ubound) to beginning(0) That's if you want to delete them too, otherwise loop whatever way you please. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted January 6, 2015 Moderators Solution Share Posted January 6, 2015 Maze573,Welcome to the AutoIt forums. I would create an array holding the 365 days and then use the _ArrayShuffle function to jumble them all up. Now you can just loop through the array and send a completely random series to your friend each time you run it. Here is a short example:#include <Array.au3> ; Create the array Global $aArray[366] ; We need an extra element for [0] ; Now fill it with the numbers in order For $i = 1 To 365 $aArray[$i] = $i Next ; And here it is just to show _ArrayDisplay($aArray, "Original", Default, 8) ; Now we shuffle the array _ArrayShuffle($aArray, 1, 0) ; And here it is shuffled _ArrayDisplay($aArray, "Shuffled", Default, 8)Please ask if you have any questions. 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 Link to comment Share on other sites More sharing options...
Maze573 Posted January 6, 2015 Author Share Posted January 6, 2015 Thank you for the unexpected fast answers, and Melba23, I already start liking this place. The idea with the array-functions you gave me both, is pretty elegant I have to say. Did not expect something as efficent as that. The only problem is, that my buddy is of the lazy type of people and I don't expect him to change his program (yes, sometimes he drives me crazy...). At the moment his program only processes one date at a time, entered in an input field in his stupid interface... So is there a way to pick for example number 1 out of the array and enter it in the field with the Send-Function, in the next loop send number 2 out of the array, number 3,...? (When I have some more free time in a few weeks I will maybe change his program myself, but for the moment i will have to do it that way...) Another problem would just be an extra (as I have the feeling I used your time already enough with my beginner problems): A girl from my class is working on a horoscope program which can only process the numbers if they have 3 digits (001,002,..099,365). Is there a way to bring the numbers in that format? Otherwise I tried to avoid the problem by starting at 101 and going to 465 (and later converting it to the right date in her program), but it was not very sucessfull. I am obviously to stupid to do it like the examples in "Dim / Global / Local / Const"and i can't see my mistake: #include <Array.au3> Global $aArray[100]...[466] For $i = 101 To 465 $aArray[$i] = $i Next _ArrayShuffle($aArray, 1, 0) _ArrayDisplay($aArray, "Random", Default, 8) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 6, 2015 Moderators Share Posted January 6, 2015 Maze573,Second question first:#include <Array.au3> Global $aArray[366] For $i = 1 To 365 $aArray[$i] = StringFormat("%03i", $i) Next _ArrayShuffle($aArray, 1, 0) _ArrayDisplay($aArray, "Random", Default, 8)Look at StringFormat in the Help file to work out how it was done. As to the first question, I do not understand how the scripts written by yourself and your buddy interact. You speak of "an input field" - is it an entirely separate process where you have to enter the number manually? If so then you could make a separate GUI which tells you the number to enter - you would need a simple label to display the value and a button to show the next in line. Give it a go and see what you can produce - you know where we are if you run into difficulties. Of course, you could also look at entering the value programmatically - that is why AutoIt was created after all! 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 Link to comment Share on other sites More sharing options...
willichan Posted January 6, 2015 Share Posted January 6, 2015 Maze573, The first problem is with your array declaration. You are trying to define your array with elements in a range. Unfortunately, it does not work that way. You need to specify how many elements you want. The element ids will always start with 0. So your array should be defined as Global $aArray[365] Why 365? You are wanting numbers from 101 to 465. That is 365 numbers (465 minus the 100 numbers you are skipping). Now, remembering that array ids start from 0 not 1, you will be working with an ID range from 0 to 364. So, how do you get your desired 3 digit numbers now? Just add 101 to your index. For $i = 0 To 364 ;loop through your valid id range $aArray[$i] = $i + 101 ;add your base number to the assigned value Next Be sure to read through the help file to understand how arrays work. In the help file, go to "Language Reference", then to "Variables". Arrays will be explained in that section. My UDFs: Barcode Libraries, Automate creation of any type of project folder, File Locking with Cooperative Semaphores, Inline binary files, Continue script after reboot, WinWaitMulti, Name Aggregator, Enigma, CornedBeef Hash Link to comment Share on other sites More sharing options...
Maze573 Posted January 7, 2015 Author Share Posted January 7, 2015 (edited) Alright, I think I made my homework for the second question. I got both solutions running in a test with my program. Melba23, StringFormat in the Help File was the key, thank you for that! I also like the other Type and Flag Specifications shown in the examples, could be very useful for future programs. willichan, your solution is pretty cool too! It will help me when I maybe later add a function with dates of birth and I don't want to start in the year 0001 but 1990 for example. And after reading the Help File I (hopefully) understand now how arrays work, at least the basics. For example the possibility to make arrays multidimensional seems very impressive for future projects, but one after another with my basic knowledge.. Ok and the first question: Melba23, you are totally right, there would be dozens of better and smarter ways to accomplish the goal to transfer random numbers from 1 to 365 to another program (or combining both programs, or any other solution). But that's when our teacher comes into the game. The whole set of programs (one tells you that your birthday, for example April 17, is day number 103 of the year, another one sorts the random days into months and weeks, one is a horoscope program,...) is for an open day presentation at our school, where primary school kids visit each classroom and decide wheter they want to go to that or that secondary school. She wants that my program moves the mouse and presses the keys totally spooky without anyone touching keyboard or mouse. And our teacher thinks that we can impress these kids (grown up with computers, consoles and most of them with a smartphone bigger than their hands) with a cursor moving by itself... A bit childish, but that's how she is... MouseMove ( 988, 513, 30) Sleep(1200) MouseClick("left",988,513,1) Sleep(1200) Send(???????) ;how to combine the array and the send command with always one number sent? Sleep(8000) ;enough time for the kids to see the number and if it is their birthday Send("{ENTER}") ;next loop... The problem is now, how I can let the program type the random numbers in the input field one by one (but still no number twice), so that the kids can see every number entered? Is there any way to use all the numbers from the shuffled array and transfer them to the other program one by one trough a simple "send" command? Edited January 7, 2015 by Maze573 Link to comment Share on other sites More sharing options...
JohnOne Posted January 7, 2015 Share Posted January 7, 2015 (edited) Yes, of course, but ControlSend is always better Have a look in the help file and its example to see how it works, and try to apply it to this other program's control. Edited January 7, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Maze573 Posted January 7, 2015 Author Share Posted January 7, 2015 (edited) Allright, I solved my first problem: (MsgBox is just for testing, later I will use the ControlSend, but I have to use the AutoIt Window Info first on my budies program) $iCount = 0 #include <Array.au3> Global $aArray[366] For $i = 1 To 365 $aArray[$i] = StringFormat("%03i", $i) Next _ArrayShuffle($aArray, 1, 0) While 1 $iCount += 1 MsgBox(0, "Array", $aArray[$iCount]) sleep(10) Wend Gets me all the dates one by one from the array. Thanky you again to everybody, using an array was the key! Maze573 Edited January 7, 2015 by Maze573 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 7, 2015 Moderators Share Posted January 7, 2015 Maze573,Why not use a second loop: #include <Array.au3> #include <MsgBoxConstants.au3> Global $aArray[366] For $i = 1 To 365 $aArray[$i] = StringFormat("%03i", $i) Next _ArrayShuffle($aArray, 1, 0) For $iCount = 1 To 365 MsgBox($MB_SYSTEMMODAL, "Array", $aArray[$iCount]) NextM23 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 Link to comment Share on other sites More sharing options...
Maze573 Posted January 7, 2015 Author Share Posted January 7, 2015 Maze573, Why not use a second loop: #include <Array.au3> #include <MsgBoxConstants.au3> Global $aArray[366] For $i = 1 To 365 $aArray[$i] = StringFormat("%03i", $i) Next _ArrayShuffle($aArray, 1, 0) For $iCount = 1 To 365 MsgBox($MB_SYSTEMMODAL, "Array", $aArray[$iCount]) Next M23 True, I guess that's the better solution. I'm just pretty happy now that it finally works as I want it to. 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