vin1 Posted February 1, 2016 Posted February 1, 2016 I have a script that gives 4 results at a time through output boxes. I want to write the results to a text file with time stamp and text from a fifth input box this should be written in the text file from the example screenshot 01/02/2016 02:15:30: Sample Input Box 01/02/2016 02:15:30: 6 01/02/2016 02:15:30: 4 01/02/2016 02:15:30: 4 01/02/2016 02:15:30: 15 this is the script expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> Global $result1s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result2s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result3s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result4s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] _Main() Func _Main() Local $button1 Local $output, $die, $msg, $results1, $results2, $results3, $results1 GUICreate("test", 600, 200, -1, -1) $button1 = GUICtrlCreateButton("Result", 150, 150, 50, 30) $output1 = GUICtrlCreateInput("", 60, 10, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("1", 5, 12) $output2 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("2", 5, 32) $output3 = GUICtrlCreateInput("", 60, 50, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("3", 5, 52) $output4 = GUICtrlCreateInput("", 60, 70, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("4", 5, 72) GUICtrlCreateInput("Sample Input Box", 60, 90, 450, 20) $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 19, 1) GUICtrlSetData($output1, $result1s[$results1-1]) $results2 = Random(1, 19, 1) GUICtrlSetData($output2, $result2s[$results2-1]) $results3 = Random(1, 19, 1) GUICtrlSetData($output3, $result3s[$results3-1]) $results4 = Random(1, 19, 1) GUICtrlSetData($output4, $result4s[$results4-1]) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main thanks a lot in advance
AutoBert Posted February 1, 2016 Posted February 1, 2016 Read GUICtrlRead, FileOpen, FileWrite/FileWriteLine, FileClose and test the examples for them.
vin1 Posted February 2, 2016 Author Posted February 2, 2016 (edited) I added some code but I get an empty text file expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <File.au3> Global $result1s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result2s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result3s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result4s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] _Main() Func _Main() Local $button1 Local $output, $die, $msg, $results1, $results2, $results3, $results1 Local $file = FileOpen("test.txt", 1) GUICreate("test", 600, 200, -1, -1) $button1 = GUICtrlCreateButton("Result", 150, 150, 50, 30) $output1 = GUICtrlCreateInput("", 60, 10, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("1", 5, 12) $output2 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("2", 5, 32) $output3 = GUICtrlCreateInput("", 60, 50, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("3", 5, 52) $output4 = GUICtrlCreateInput("", 60, 70, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("4", 5, 72) GUICtrlCreateInput("Sample Input Box", 60, 90, 450, 20) $read1 = GUICtrlRead($output1) $read2 = GUICtrlRead($output2) $read3 = GUICtrlRead($output3) $read4 = GUICtrlRead($output4) $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 19, 1) GUICtrlSetData($output1, $result1s[$results1-1]) $results2 = Random(1, 19, 1) GUICtrlSetData($output2, $result2s[$results2-1]) $results3 = Random(1, 19, 1) GUICtrlSetData($output3, $result3s[$results3-1]) $results4 = Random(1, 19, 1) GUICtrlSetData($output4, $result4s[$results4-1]) FileWriteLine($file, $read1) FileWriteLine($file, $read2) FileWriteLine($file, $read3) FileWriteLine($file, $read4) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main how to make it work? thanks again in advance Edited February 2, 2016 by vin1
Jfish Posted February 2, 2016 Posted February 2, 2016 (edited) FileClose when you are done writing stuff to the file. Edited February 2, 2016 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Jfish Posted February 2, 2016 Posted February 2, 2016 You may also want to look at _NowDate ( ) and _NowTime () if you want to add a timestamp .. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
AutoBert Posted February 2, 2016 Posted February 2, 2016 and most importand: use GuiCtrlRead direct before writing. In your case the variables $read1... $read4 are empty, so as the Inputcontrols does at the time you are reading.
vin1 Posted February 2, 2016 Author Posted February 2, 2016 (edited) how to instead of FileWriteLine($file, "text") make FileWriteLine($file, $read1) work Edited February 2, 2016 by vin1
l3ill Posted February 2, 2016 Posted February 2, 2016 _FileWriteLog would work good here too... My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example
Jfish Posted February 2, 2016 Posted February 2, 2016 (edited) You need to read AFTER you populate the data in the control (that is what @AutoBert meant in his post above). Right now you are reading it - but it is empty. Try this: ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 19, 1) GUICtrlSetData($output1, $result1s[$results1-1]) $read1 = GUICtrlRead($output1) $results2 = Random(1, 19, 1) GUICtrlSetData($output2, $result2s[$results2-1]) $read2 = GUICtrlRead($output2) $results3 = Random(1, 19, 1) GUICtrlSetData($output3, $result3s[$results3-1]) $read3 = GUIctrlRead($output3) $results4 = Random(1, 19, 1) GUICtrlSetData($output4, $result4s[$results4-1]) $read4 = GUICtrlRead($output4) FileWriteLine($file, $read1) FileWriteLine($file, $read2) FileWriteLine($file, $read3) FileWriteLine($file, $read4) FileClose($file) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main You see the $read values have all been moved down - after the controls they are reading have been populated with data. Then the file is closed when we are done writing to it. I tested it and it works so if you change the code at the bottom to what I have above it will work. Edited February 2, 2016 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
vin1 Posted February 2, 2016 Author Posted February 2, 2016 how to add a date stamp to it for every line of $read#
Jfish Posted February 2, 2016 Posted February 2, 2016 ;Untested: FileWriteLine($file, _NowDate( )& " " & _nowTime() & " " $read1) Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
vin1 Posted February 2, 2016 Author Posted February 2, 2016 _NowDate gives an error, "Error in expression"
Jfish Posted February 2, 2016 Posted February 2, 2016 Are you using the Date.au3 UDF? Look at the function in the help file. You need to include that UDF in your script. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
kylomas Posted February 2, 2016 Posted February 2, 2016 vin1, Show the code that errors. kylomas 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
vin1 Posted February 2, 2016 Author Posted February 2, 2016 expandcollapse popup#include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <File.au3> #include <Date.au3> Global $result1s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result2s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result3s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] Global $result4s[19]=["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"] _Main() Func _Main() Local $button1 Local $output, $die, $msg, $results1, $results2, $results3, $results1 Local $file = FileOpen("test.txt", 1) GUICreate("test", 600, 200, -1, -1) $button1 = GUICtrlCreateButton("Result", 460, 110, 50, 30) $output1 = GUICtrlCreateInput("", 60, 10, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("1", 5, 12) $output2 = GUICtrlCreateInput("", 60, 30, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("2", 5, 32) $output3 = GUICtrlCreateInput("", 60, 50, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("3", 5, 52) $output4 = GUICtrlCreateInput("", 60, 70, 450, 20, BitOR($ES_CENTER, $ES_READONLY)) GUICtrlCreateLabel("4", 5, 72) GUICtrlCreateInput("Sample Input Box", 60, 90, 450, 20) $die = GUICtrlCreateLabel("", 700, 500, 700, 20, $SS_SUNKEN) GUICtrlSetFont($output, 8, 800, "", "Verdana") GUISetState() ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 19, 1) GUICtrlSetData($output1, $result1s[$results1-1]) $read1 = GUICtrlRead($output1) $results2 = Random(1, 19, 1) GUICtrlSetData($output2, $result2s[$results2-1]) $read2 = GUICtrlRead($output2) $results3 = Random(1, 19, 1) GUICtrlSetData($output3, $result3s[$results3-1]) $read3 = GUIctrlRead($output3) $results4 = Random(1, 19, 1) GUICtrlSetData($output4, $result4s[$results4-1]) $read4 = GUICtrlRead($output4) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " $read1) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " $read2) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " $read3) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " $read4) FileClose($file) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main I want the code to write to the text file so the contents look like this (like in the first post): 01/02/2016 02:15:30: Sample Input Box 01/02/2016 02:15:30: 6 01/02/2016 02:15:30: 4 01/02/2016 02:15:30: 4 01/02/2016 02:15:30: 15
Jfish Posted February 2, 2016 Posted February 2, 2016 I was missing an "&" before the last part of the FileWriteLine (just before $read1, etc). Try this: ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() Select Case $msg = $button1 $results1 = Random(1, 19, 1) GUICtrlSetData($output1, $result1s[$results1-1]) $read1 = GUICtrlRead($output1) $results2 = Random(1, 19, 1) GUICtrlSetData($output2, $result2s[$results2-1]) $read2 = GUICtrlRead($output2) $results3 = Random(1, 19, 1) GUICtrlSetData($output3, $result3s[$results3-1]) $read3 = GUIctrlRead($output3) $results4 = Random(1, 19, 1) GUICtrlSetData($output4, $result4s[$results4-1]) $read4 = GUICtrlRead($output4) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read1) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read2) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read3) FileWriteLine($file, _NowDate()& " " & _nowTime() & " " &$read4) FileClose($file) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EndFunc ;==>_Main It will produce this: Quote 2/2/2016 5:14:20 PM 10 2/2/2016 5:14:20 PM 19 2/2/2016 5:14:20 PM 9 2/2/2016 5:14:20 PM 14 Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
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