JusKus Posted April 29, 2020 Share Posted April 29, 2020 Hello, I am currently trying to get a code to work, which is supposed to run a random command in my code. Global $aCommand[6] $aCommand[0] = ConsoleWrite ("Option 1") $aCommand[1] = ConsoleWrite ("Option 2") $aCommand[2] = ConsoleWrite ("Option 3") $aCommand[3] = ConsoleWrite ("Option 4") $aCommand[4] = ConsoleWrite ("Option 5") $aCommand[5] = ConsoleWrite ("Option 6") This is my first attempt, but i cant get to run one of the commands. What is the proper code for that? Its embarassing but those are the lines that i tried: Call $aCommand[Random(1,6,1)] Background of my question: I am writing a tool, which outputs random sentences into an input field. So that it does not always put the same sentence over and over again i want to randomize them and send one out of 6 for example. If you click the button again it gives you another sentence. I hope i could make it clear as english is not my mother tongue. Thanks in advance. Link to comment Share on other sites More sharing options...
faustf Posted April 29, 2020 Share Posted April 29, 2020 (edited) try to use https://www.autoitscript.com/autoit3/docs/functions/Random.htm load with https://www.autoitscript.com/autoit3/docs/functions/FileReadToArray.htm a word in page .txt , after with random , call a segment of array and insert inside of input use F1 in scite Edited April 29, 2020 by faustf JusKus 1 Link to comment Share on other sites More sharing options...
Gianni Posted April 29, 2020 Share Posted April 29, 2020 ... one of possible ways ... #include <GUIConstantsEx.au3> Example() Func Example() ; populate the array with sentences Local $aSentences[] = ["Option 1", "Option 2", "Option 3", "Option 4", "Option 5", "Option 6"] Local $hGui = GUICreate("Random sentence") ; create the gui Local $hField = GUICtrlCreateInput('', 5, 5); the input field Local $hButton = GUICtrlCreateButton("Oracle", 5, 35) ; the button GUISetState() ; show the gui ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hButton ; if the button was clicked to the following ; Change sentence in the input field GUICtrlSetData($hField, $aSentences[Random(0, UBound($aSentences) - 1, 1)]) EndSwitch WEnd EndFunc ;==>Example JusKus 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
careca Posted April 29, 2020 Share Posted April 29, 2020 Your original idea was not far from possible, thing is, when you set the array variables, you included the consolewrites, that was the problem. The idea when you set the variables is you set the actual values you want to use. Global $aCommand[6] $aCommand[0] = "Option 1" $aCommand[1] = "Option 2" $aCommand[2] = "Option 3" $aCommand[3] = "Option 4" $aCommand[4] = "Option 5" $aCommand[5] = "Option 6" $RNum = Random(0,5,1) ConsoleWrite($aCommand[$RNum]&@CRLF) Sway and JusKus 2 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
JusKus Posted April 30, 2020 Author Share Posted April 30, 2020 Local $Empfehlung[4] $Empfehlung[0] = "Option A " $Empfehlung[1] = "Option B " $Empfehlung[2] = "Option C" $Empfehlung[3] = "Option D" ClipPut($Empfehlung[Random(0, 3, 1)]) Thank you for all your contributions. This is what i used and this works absolutely perfect. Thank you so much guys. careca 1 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