akfourtyseven Posted February 3, 2009 Share Posted February 3, 2009 How do you write a text entered into an input box onto a text file. For example, #include <GuiConstants.au3> #include <Inet.au3> #include <GUIConstantsEx.au3> ; GUI Creation GUICreate("Data", 500, 420) GUICtrlCreateTabItem("Data") $labelnaam = GUICtrlCreateLabel("Name : ", 60, 40) $Button_word = GUICtrlCreateButton("Write", 400, 350) $input_naam = GUICtrlCreateInput("", 100, 40, 130, 20) ; GUI Show GUISetState(@SW_SHOW) $file = FileOpen("ak.txt",0) While 1 $msg = GUIGetMsg() Select Case $msg = $Button_word $read_input = GUICtrlRead($input_naam) FileWrite($file, "12"&$Read_Input&"34") FileClose($file) EndSelect If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd It works when I make it display the input on Message box but it doesn't write it to a file, What is the problem?! There are 10 kinds of people, those who understand me and those who don't. Link to comment Share on other sites More sharing options...
Manjish Posted February 3, 2009 Share Posted February 3, 2009 change it to this.. u r missing an exitloop. so ur while loop never ends.. it keeps on executing. #include <GuiConstants.au3> #include <Inet.au3> #include <GUIConstantsEx.au3> ; GUI Creation GUICreate("Data", 500, 420) GUICtrlCreateTabItem("Data") $labelnaam = GUICtrlCreateLabel("Name : ", 60, 40) $Button_word = GUICtrlCreateButton("Write", 400, 350) $input_naam = GUICtrlCreateInput("", 100, 40, 130, 20) ; GUI Show GUISetState(@SW_SHOW) $file = FileOpen("c:\ak.txt",2) While 1 $msg = GUIGetMsg() if $msg = $Button_word Then $read_input = GUICtrlRead($input_naam) FileWrite($file, "12"&$Read_Input&"34") FileClose($file) ExitLoop Endif If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
akfourtyseven Posted February 3, 2009 Author Share Posted February 3, 2009 change it to this.. u r missing an exitloop. so ur while loop never ends.. it keeps on executing. #include <GuiConstants.au3> #include <Inet.au3> #include <GUIConstantsEx.au3> ; GUI Creation GUICreate("Data", 500, 420) GUICtrlCreateTabItem("Data") $labelnaam = GUICtrlCreateLabel("Name : ", 60, 40) $Button_word = GUICtrlCreateButton("Write", 400, 350) $input_naam = GUICtrlCreateInput("", 100, 40, 130, 20) ; GUI Show GUISetState(@SW_SHOW) $file = FileOpen("c:\ak.txt",2) While 1 $msg = GUIGetMsg() if $msg = $Button_word Then $read_input = GUICtrlRead($input_naam) FileWrite($file, "12"&$Read_Input&"34") FileClose($file) ExitLoop Endif If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd I have changed it and still no progress.. I have managed to make it write but it only writes the default value of the input box, There are 10 kinds of people, those who understand me and those who don't. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2009 Moderators Share Posted February 3, 2009 akfourtyseven,1. Perhaps if you opened your file in Write mode?Mode (read or write) to open the file in.Can be a combination of the following: 0 = Read mode 1 = Write mode (append to end of file) 2 = Write mode (erase previous contents)2. You are also closing your file after the first write. Put FileClose as part of your exit code.3. You are not writing what you read - use the same spelling for the GUICtrlRead and FileWrite.Try this:#include <GuiConstants.au3> #include <Inet.au3> #include <GUIConstantsEx.au3> ; GUI Creation GUICreate("Data", 500, 420) GUICtrlCreateTabItem("Data") $labelnaam = GUICtrlCreateLabel("Name : ", 60, 40) $Button_word = GUICtrlCreateButton("Write", 400, 350) $input_naam = GUICtrlCreateInput("", 100, 40, 130, 20) ; GUI Show GUISetState(@SW_SHOW) $file = FileOpen("ak.txt",1) While 1 $msg = GUIGetMsg() Select Case $msg = $Button_word $read_input = GUICtrlRead($input_naam) FileWrite($file, "12" & $read_input & "34") Case $msg = $GUI_EVENT_CLOSE FileClose($file) ExitLoop EndSelect WEndM23  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...
Manjish Posted February 3, 2009 Share Posted February 3, 2009 Hey I just tested with the above code. It works perfectly well. It creates a file in C drive, named ak.txt. and writes 12*****34. **** represents i/p. What exactly is the problem. Is it creating the file or not. n if it is then what is it writing to the file. Also plz tell me the version u r using [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
akfourtyseven Posted February 3, 2009 Author Share Posted February 3, 2009 akfourtyseven, 1. Perhaps if you opened your file in Write mode? Mode (read or write) to open the file in. Can be a combination of the following: 0 = Read mode 1 = Write mode (append to end of file) 2 = Write mode (erase previous contents) 2. You are also closing your file after the first write. Put FileClose as part of your exit code. 3. You are not writing what you read - use the same spelling for the GUICtrlRead and FileWrite. Try this:#include <GuiConstants.au3> #include <Inet.au3> #include <GUIConstantsEx.au3> ; GUI Creation GUICreate("Data", 500, 420) GUICtrlCreateTabItem("Data") $labelnaam = GUICtrlCreateLabel("Name : ", 60, 40) $Button_word = GUICtrlCreateButton("Write", 400, 350) $input_naam = GUICtrlCreateInput("", 100, 40, 130, 20) ; GUI Show GUISetState(@SW_SHOW) $file = FileOpen("ak.txt",1) While 1 $msg = GUIGetMsg() Select Case $msg = $Button_word $read_input = GUICtrlRead($input_naam) FileWrite($file, "12" & $read_input & "34") Case $msg = $GUI_EVENT_CLOSE FileClose($file) ExitLoop EndSelect WEnd M23 Thanx! That worked!!! There are 10 kinds of people, those who understand me and those who don't. Link to comment Share on other sites More sharing options...
akfourtyseven Posted February 3, 2009 Author Share Posted February 3, 2009 Hey I just tested with the above code. It works perfectly well. It creates a file in C drive, named ak.txt. and writes 12*****34. **** represents i/p.What exactly is the problem.Is it creating the file or not. n if it is then what is it writing to the file.Also plz tell me the version u r using@ManjishSorry for Double posting but I just saw your post after I posted my reply,I didn't know that it created ak.txt in C drive because my first script created ak.txt on the same folder with the script and I looked for ak.txt on the wrong place. Sorry for the misunderstanding. There are 10 kinds of people, those who understand me and those who don't. 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