Hylia Posted August 23, 2014 Posted August 23, 2014 Hi, what I want to do with AutoIT is the following: I want to roll a dice then I write the result into an array and then I want the result to be shown in the big text box; for one result this is easy to do, however, I want the next result to appear above or underneath it so I can see both results after each other and I want to keep doing this for all the rolls that are next. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 353, 438, 192, 124) $TextWindow = GUICtrlCreateEdit("", 8, 8, 225, 417) GUICtrlSetData(-1, "TextWindow") $bDice = GUICtrlCreateButton("Roll the Dice!", 256, 384, 81, 33) $lResult1 = GUICtrlCreateLabel("Result1", 248, 16, 40, 17) $lResult2 = GUICtrlCreateLabel("Result2", 248, 64, 40, 17) $lResult3 = GUICtrlCreateLabel("Result3", 248, 112, 40, 17) $Result1 = GUICtrlCreateInput("", 304, 16, 33, 21) $Result2 = GUICtrlCreateInput("", 304, 64, 33, 21) $Result3 = GUICtrlCreateInput("", 304, 112, 33, 21) GUISetState(@SW_SHOW) Global $D Global $R[10] Global $i = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bDice Roll() EndSwitch WEnd Func Roll() $D = Random (1, 6, 1) $R[$i] = $D GUICtrlSetData($TextWindow, $R[$i] & $R[$i+1]) ;This doesn't do anything ;GUICtrlSetData($TextWindow, $R[$i] & $R[$i+1] &) nor this ;GUICtrlSetData($TextWindow, $R[$i], $R[$i+1]) or this GUICtrlSetData($Result1, $R[0]) GUICtrlSetData($Result2, $R[1]) GUICtrlSetData($Result3, $R[2]) $i = $i + 1 EndFunc So, basicly what I've managed to achieve is I can only display one number at a time in the comment box, or I have to manually add all the boxes I want to display the previous results, I would think there's an easier way for this, can anyone tell me what I've missed?
Danyfirex Posted August 23, 2014 Posted August 23, 2014 I don't sure. did you mean this: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 353, 438, 192, 124) $TextWindow = GUICtrlCreateEdit("", 8, 8, 225, 417) ;~ GUICtrlSetData(-1, "TextWindow") $bDice = GUICtrlCreateButton("Roll the Dice!", 256, 384, 81, 33) $lResult1 = GUICtrlCreateLabel("Result1", 248, 16, 40, 17) $lResult2 = GUICtrlCreateLabel("Result2", 248, 64, 40, 17) $lResult3 = GUICtrlCreateLabel("Result3", 248, 112, 40, 17) $Result1 = GUICtrlCreateInput("", 304, 16, 33, 21) $Result2 = GUICtrlCreateInput("", 304, 64, 33, 21) $Result3 = GUICtrlCreateInput("", 304, 112, 33, 21) GUISetState(@SW_SHOW) Global $D Global $R[10] Global $i = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bDice Roll() EndSwitch WEnd Func Roll() $D = Random (1, 6, 1) $R[$i] = $D GUICtrlSetData( $TextWindow , GUICtrlRead($TextWindow) & $R[$i] & $R[$i+1] & @CRLF) ;This doesn't do anything ;GUICtrlSetData($TextWindow, $R[$i] & $R[$i+1] &) nor this ;GUICtrlSetData($TextWindow, $R[$i], $R[$i+1]) or this GUICtrlSetData($Result1, $R[0]) GUICtrlSetData($Result2, $R[1]) GUICtrlSetData($Result3, $R[2]) $i = $i + 1 EndFunc Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut
Solution kylomas Posted August 24, 2014 Solution Posted August 24, 2014 (edited) Hylia, This may give you some ideas... expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> local $gui = guicreate('Roll The Dice',200,200) local $display = guictrlcreateedit('',10,10,100,160, BitOR($WS_VSCROLL, $ES_READONLY)) ; create a group to hold the frequency count controls local $g1 = guictrlcreategroup('Frequency',115,05,80,160) ; create an array to hold the frequency count control id's local $aRolls[6] ; create static controls for frequency counts for $1 = 1 to 6 guictrlcreatelabel('#' & $1 & ' - ',130,$1*15+15,20,15) $aRolls[$1-1] = guictrlcreatelabel('',145,$1*15+15,20,15,bitor($SS_SUNKEN,$SS_CENTER)) next local $roller = GUICtrlCreateButton("Roll the Dice!" & @CRLF, 10,180,180,20) ; do roll routine if the enter key is pressed local $Enter = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; allows Enter key to actuate a control ($Enter) Dim $aAccelKeys[1][2] = [["{ENTER}", $Enter]] GUISetAccelerators($aAccelKeys) While 1 switch guigetmsg() Case $GUI_EVENT_CLOSE Exit ; do roll routine if either Roll button is clicked or the Enter key is pressed case $roller, $Enter _Roll() EndSwitch WEnd func _Roll() static $roll_number = 1 ; will persist between calls local $tRoll = random(1,6,1) ; will change between calls ; display the current roll guictrlsetdata($display,'Roll # ' & stringformat('%03i',$roll_number) & ' = ' & $tRoll & @CRLF,1) $roll_number += 1 ; update the frequency count by adding 1 to the matching control guictrlsetdata($aRolls[$tRoll-1], guictrlread($aRolls[$tRoll-1]) + 1) endfunc kylomas edit: added ENTER key as accelerator Edited August 24, 2014 by kylomas Hylia 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Hylia Posted August 24, 2014 Author Posted August 24, 2014 Hylia, This may give you some ideas... expandcollapse popup#include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> local $gui = guicreate('Roll The Dice',200,200) local $display = guictrlcreateedit('',10,10,100,160, BitOR($WS_VSCROLL, $ES_READONLY)) ; create a group to hold the frequency count controls local $g1 = guictrlcreategroup('Frequency',115,05,80,160) ; create an array to hold the frequency count control id's local $aRolls[6] ; create static controls for frequency counts for $1 = 1 to 6 guictrlcreatelabel('#' & $1 & ' - ',130,$1*15+15,20,15) $aRolls[$1-1] = guictrlcreatelabel('',145,$1*15+15,20,15,bitor($SS_SUNKEN,$SS_CENTER)) next local $roller = GUICtrlCreateButton("Roll the Dice!" & @CRLF, 10,180,180,20) ; do roll routine if the enter key is pressed local $Enter = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; allows Enter key to actuate a control ($Enter) Dim $aAccelKeys[1][2] = [["{ENTER}", $Enter]] GUISetAccelerators($aAccelKeys) While 1 switch guigetmsg() Case $GUI_EVENT_CLOSE Exit ; do roll routine if either Roll button is clicked or the Enter key is pressed case $roller, $Enter _Roll() EndSwitch WEnd func _Roll() static $roll_number = 1 ; will persist between calls local $tRoll = random(1,6,1) ; will change between calls ; display the current roll guictrlsetdata($display,'Roll # ' & stringformat('%03i',$roll_number) & ' = ' & $tRoll & @CRLF,1) $roll_number += 1 ; update the frequency count by adding 1 to the matching control guictrlsetdata($aRolls[$tRoll-1], guictrlread($aRolls[$tRoll-1]) + 1) endfunc kylomas edit: added ENTER key as accelerator Absolutely perfect, exactly what I wanted, thanks!
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