face Posted October 9, 2013 Share Posted October 9, 2013 (edited) how can i save 30 randomly generated result values to result.txt file from 1 to 30 on the same row and spaced to 1 column each so far i have made this to start with and i also need the listbox value to control the number of rows (50+ rows) to be generated and saved in the text file when the generate button is activated so i need: working listbox generated rows 30 columns each (in the txt file) generated 50+ rows at a time (in the txt file) totally random results the text file with random result values should look like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> Global $result1s[2]=["0", "0"] Global $result2s[4]=["1", "2", "3", "4"] Global $result3s[4]=["0", "0", "0", "0"] Global $result4s[6]=["0", "0", "0", "0", "0", "0"] Global $result5s[8]=["0", "0", "0", "0", "0", "0", "0", "0"] Global $result6s[10]=["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result7s[2]=["0", "0"] Global $result8s[11]=["553", "742", "554", "538", "518", "553", "471", "511", "491", "595", "596"] Global $result9s[4]=["10000", "20000", "30000", "40000"] Global $result10s[6]=["0", "0", "0", "0", "0", "0"] Global $result11s[8]=["0", "0", "0", "0", "0", "0", "0", "0"] Global $result12s[10]=["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result13s[2]=["0", "0"] Global $result14s[4]=["1", "2", "3", "4"] Global $result15s[4]=["0", "0", "0", "0"] Global $result16s[6]=["0", "11", "12", "8", "7", "0"] Global $result17s[8]=["0", "0", "0", "0", "0", "0", "0", "0"] Global $result18s[10]=["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result19s[2]=["1", "2"] Global $result20s[4]=["0", "0", "0", "0"] Global $result21s[5]=["0", "6", "7", "1", "2"] Global $result22s[8]=["1", "2", "3", "4", "5", "6", "7", "0"] Global $result23s[4]=["0", "3", "2", "1"] Global $result24s[10]=["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result25s[2]=["0", "0"] Global $result26s[4]=["0", "149", "9", "13"] Global $result27s[4]=["30000", "50000", "2000", "2500"] Global $result28s[6]=["5", "5", "5", "5", "5", "5"] Global $result29s[8]=["1", "1", "1", "0", "0", "0", "0", "0"] Global $result30s[10]=["1", "1", "0", "0", "0", _ "0", "0", "0", "0", "0"] _Main() Func _Main() Local $button1 Local $output, $results1, $results2, $results3, $results4, $results5, $results6, $results7, $results8, _ $results9, $results10, $results11, $results12, $results13, $results14, $results15, $results16, $results17, $results18, _ $results19, $results20, $results21, $results22, $results23, $results24, $results25, $results26, $results27, $results28, $results29, $results30 GUICreate("Stats", 300, 150, -1, -1) GUICtrlCreateCombo("50", 10, 10) GUICtrlSetData(-1, "50|100|500|1000|2000|4000|", "50") $button1 = GUICtrlCreateButton("Generate", 40, 60, 50, 30) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 2, 1) $results2 = Random(1, 4, 1) $results3 = Random(1, 4, 1) $results4 = Random(1, 6, 1) $results5 = Random(1, 8, 1) $results6 = Random(1, 10, 1) $results7 = Random(1, 2, 1) $results8 = Random(1, 11, 1) $results9 = Random(1, 4, 1) $results10 = Random(1, 6, 1) $results11 = Random(1, 8, 1) $results12 = Random(1, 10, 1) $results13 = Random(1, 2, 1) $results14 = Random(1, 4, 1) $results15 = Random(1, 4, 1) $results16 = Random(1, 6, 1) $results17 = Random(1, 8, 1) $results18 = Random(1, 10, 1) $results19 = Random(1, 2, 1) $results20 = Random(1, 3, 1) $results21 = Random(1, 4, 1) $results22 = Random(1, 6, 1) $results23 = Random(1, 4, 1) $results24 = Random(1, 10, 1) $results25 = Random(1, 2, 1) $results26 = Random(1, 4, 1) $results27 = Random(1, 4, 1) $results28= Random(1, 6, 1) $results29 = Random(1, 8, 1) $results30 = Random(1, 10, 1) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main thanks in advance Edited October 9, 2013 by face Link to comment Share on other sites More sharing options...
jdelaney Posted October 9, 2013 Share Posted October 9, 2013 (edited) Ah, finally picked it up (had to read that a few times). you have a collection of arrays which you want to randomly select values from. Easiest way would be a nested loop (2 loops)...will post response in a few minutes. expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <File.au3> Global $result1s[2] = ["0", "0"] Global $result2s[4] = ["1", "2", "3", "4"] Global $result3s[4] = ["0", "0", "0", "0"] Global $result4s[6] = ["0", "0", "0", "0", "0", "0"] Global $result5s[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $result6s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result7s[2] = ["0", "0"] Global $result8s[11] = ["553", "742", "554", "538", "518", "553", "471", "511", "491", "595", "596"] Global $result9s[4] = ["10000", "20000", "30000", "40000"] Global $result10s[6] = ["0", "0", "0", "0", "0", "0"] Global $result11s[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $result12s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result13s[2] = ["0", "0"] Global $result14s[4] = ["1", "2", "3", "4"] Global $result15s[4] = ["0", "0", "0", "0"] Global $result16s[6] = ["0", "11", "12", "8", "7", "0"] Global $result17s[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $result18s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result19s[2] = ["1", "2"] Global $result20s[4] = ["0", "0", "0", "0"] Global $result21s[5] = ["0", "6", "7", "1", "2"] Global $result22s[8] = ["1", "2", "3", "4", "5", "6", "7", "0"] Global $result23s[4] = ["0", "3", "2", "1"] Global $result24s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result25s[2] = ["0", "0"] Global $result26s[4] = ["0", "149", "9", "13"] Global $result27s[4] = ["30000", "50000", "2000", "2500"] Global $result28s[6] = ["5", "5", "5", "5", "5", "5"] Global $result29s[8] = ["1", "1", "1", "0", "0", "0", "0", "0"] Global $result30s[10] = ["1", "1", "0", "0", "0", _ "0", "0", "0", "0", "0"] $file = @DesktopDir & "\output.txt" _Main() Func _Main() Local $button1 Local $output, $results1, $results2, $results3, $results4, $results5, $results6, $results7, $results8, _ $results9, $results10, $results11, $results12, $results13, $results14, $results15, $results16, $results17, $results18, _ $results19, $results20, $results21, $results22, $results23, $results24, $results25, $results26, $results27, $results28, $results29, $results30 GUICreate("Stats", 300, 150, -1, -1) $combo = GUICtrlCreateCombo("50", 10, 10) GUICtrlSetData(-1, "50|100|500|1000|2000|4000|", "50") $button1 = GUICtrlCreateButton("Generate", 40, 60, 50, 30) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $button1 _FileCreate($file) $hfile = FileOpen($file, 1) For $i = 1 To GUICtrlRead($combo) $string = "" For $j = 1 To 30 $array = Eval("result" & $j & "s") $temp = Random(0, UBound($array) - 1, 1) If $j = 1 Then $string = $array[$temp] Else $string &= @TAB & $array[$temp] EndIf Next ConsoleWrite($string & @CRLF) FileWriteLine($hfile, $string) Next FileClose($hfile) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main Another way, would be to have an array of arrays...then you can loop, create a temp array with the value array from the array of arrays (let's see how many times I can say array ), and then use that to drive the random like in my example. But eval works just as well, since they are all following the same name conventions. There are lots of gui things you should do...like disable the button until the end of the loops, and then re-enable. I just wanted to help with the logic, not the structure Edited October 9, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
face Posted October 9, 2013 Author Share Posted October 9, 2013 thanks a lot it works well can an option of no repeat be added for specific columns? Link to comment Share on other sites More sharing options...
Solution jdelaney Posted October 9, 2013 Solution Share Posted October 9, 2013 (edited) Sure. A little trickier. Will need an array of the last record, and verify the subscript to write does not match....there will be the possibility of dupes though, since many of your arrays have only one digit... here ya go: expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <File.au3> Global $result1s[2] = ["0", "0"] Global $result2s[4] = ["1", "2", "3", "4"] Global $result3s[4] = ["0", "0", "0", "0"] Global $result4s[6] = ["0", "0", "0", "0", "0", "0"] Global $result5s[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $result6s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result7s[2] = ["0", "0"] Global $result8s[11] = ["553", "742", "554", "538", "518", "553", "471", "511", "491", "595", "596"] Global $result9s[4] = ["10000", "20000", "30000", "40000"] Global $result10s[6] = ["0", "0", "0", "0", "0", "0"] Global $result11s[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $result12s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result13s[2] = ["0", "0"] Global $result14s[4] = ["1", "2", "3", "4"] Global $result15s[4] = ["0", "0", "0", "0"] Global $result16s[6] = ["0", "11", "12", "8", "7", "0"] Global $result17s[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $result18s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result19s[2] = ["1", "2"] Global $result20s[4] = ["0", "0", "0", "0"] Global $result21s[5] = ["0", "6", "7", "1", "2"] Global $result22s[8] = ["1", "2", "3", "4", "5", "6", "7", "0"] Global $result23s[4] = ["0", "3", "2", "1"] Global $result24s[10] = ["0", "0", "0", "0", "0", _ "0", "0", "0", "0", "0"] Global $result25s[2] = ["0", "0"] Global $result26s[4] = ["0", "149", "9", "13"] Global $result27s[4] = ["30000", "50000", "2000", "2500"] Global $result28s[6] = ["5", "5", "5", "5", "5", "5"] Global $result29s[8] = ["1", "1", "1", "0", "0", "0", "0", "0"] Global $result30s[10] = ["1", "1", "0", "0", "0", _ "0", "0", "0", "0", "0"] $file = @DesktopDir & "\output.txt" _Main() Func _Main() Local $button1 Local $output, $results1, $results2, $results3, $results4, $results5, $results6, $results7, $results8, _ $results9, $results10, $results11, $results12, $results13, $results14, $results15, $results16, $results17, $results18, _ $results19, $results20, $results21, $results22, $results23, $results24, $results25, $results26, $results27, $results28, $results29, $results30 GUICreate("Stats", 300, 150, -1, -1) $combo = GUICtrlCreateCombo("50", 10, 10) GUICtrlSetData(-1, "50|100|500|1000|2000|4000|", "50") $button1 = GUICtrlCreateButton("Generate", 40, 60, 50, 30) GUISetState() Local $aHistory[30] While 1 $msg = GUIGetMsg() Select Case $msg = $button1 _FileCreate($file) $hfile = FileOpen($file, 1) For $i = 1 To GUICtrlRead($combo) $string = "" For $j = 1 To 30 $iLast = $aHistory[$j-1] $array = Eval("result" & $j & "s") Do $temp = Random(0, UBound($array) - 1, 1) Until $iLast<>$temp $aHistory[$j-1] = $temp If $j = 1 Then $string = $array[$temp] Else $string &= @TAB & $array[$temp] EndIf Next ConsoleWrite($string & @CRLF) FileWriteLine($hfile, $string) Next FileClose($hfile) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main I can say with certainty though, that none of the dupes (per column) are using the same, matching array subscript. Edited October 9, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
face Posted October 9, 2013 Author Share Posted October 9, 2013 thanks can it be made so it loads external txt file (external array data) instead of array data? at least on $result2s Link to comment Share on other sites More sharing options...
jdelaney Posted October 9, 2013 Share Posted October 9, 2013 (edited) Of course. You can make a comma separated value file. Loop through the lines (read in with _filereadtoarray), and create an array using stringsplit, when looping through the array returned from _Filereadtoarray. Give it a shot, I'll give you points as needed. meh...feeling generous: The file can be any length, where a given line has all the values you want for the array, with comma delimis...like: 100,200,300 4,5,6,7 a,b,c,d,e,f,g,h expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <File.au3> #include <Array.au3> ; These are just to show what the file must look like... $tempFile = @DesktopDir & "\temp.txt" _FileCreate($tempFile) FileWrite($tempFile,"100,200,300" & @CRLF & "4,5,6" & @CRLF & "a,b,c,d,e,f,g,h") ; This is the actual read in to the array, to drive the loops below $file = @DesktopDir & "\output.txt" Local $aLines[1] _FileReadToArray($tempFile,$aLines) For $i = 1 To UBound($aLines) - 1 $aLines[$i] = StringSplit($aLines[$i],",",2) ConsoleWrite(_ArrayToString($aLines[$i]) & @CRLF) Next _Main() Func _Main() Local $button1 Local $output GUICreate("Stats", 300, 150, -1, -1) $combo = GUICtrlCreateCombo("50", 10, 10) GUICtrlSetData(-1, "50|100|500|1000|2000|4000|", "50") $button1 = GUICtrlCreateButton("Generate", 40, 60, 50, 30,$BS_DEFPUSHBUTTON) GUISetState() Local $aHistory[30] While 1 $msg = GUIGetMsg() Select Case $msg = $button1 GUICtrlSetState($button1,$GUI_DISABLE) _FileCreate($file) $hfile = FileOpen($file, 1) For $i = 1 To GUICtrlRead($combo) $string = "" For $j = 1 To UBound($aLines)-1 $iLast = $aHistory[$j-1] $array = $aLines[$j] Do $temp = Random(0, UBound($array) - 1, 1) Until $iLast<>$temp $aHistory[$j-1] = $temp If $j = 1 Then $string = $array[$temp] Else $string &= @TAB & $array[$temp] EndIf Next ConsoleWrite($string & @CRLF) FileWriteLine($hfile, $string) Next FileClose($hfile) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() GUICtrlSetState($button1,$GUI_ENABLE) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main edit: of course, you won't need all the array declarations, now (edited them out...added in the button disable/enable...needed for the larger combo values...especially with large amounts of 'columns' to add...sending Enter will default to clicking the button, also.) Edited October 9, 2013 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
face Posted October 9, 2013 Author Share Posted October 9, 2013 thanks again 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