chacoya121 Posted April 14, 2017 Posted April 14, 2017 (edited) #include <File.au3> HotKeySet("{Esc}", "_exit") HotKeySet("{Home}","Start") Global $ifile = FileOpen(@ScriptDir & "\text1.txt") while 1 Sleep(100) WEnd Func Start() $random = Random(1,10,1) $line = FileReadLine($ifile,$random) $ifile = FileOpen(@ScriptDir & "\text1.txt", 2) _FileWriteToLine($ifile,$random,"",1) $countline = _FileCountLines($ifile) EndFunc Func _exit() Exit EndFunc i try to overwrite the line from text but its clear all can someone help plz Edited April 14, 2017 by Melba23 Added code tags
KickStarter15 Posted April 14, 2017 Posted April 14, 2017 @chacoya121, Try below. Change the value "1" to "True" that will solved this issue. $random = Random(1,10,1) _FileWriteToLine(@ScriptDir & "\text1.txt", $random, "my replacement line", True) Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.
kylomas Posted April 14, 2017 Posted April 14, 2017 chacoya121, Try this for your filewritetoline... _FileWriteToLine($ifile,$random,$line,1) 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
Moderators Melba23 Posted April 14, 2017 Moderators Posted April 14, 2017 chacoya121, When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 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
KickStarter15 Posted April 14, 2017 Posted April 14, 2017 @kylomas, Sorry, but I think "$line" was used to read the line in the first post. So, this will not add to _FileWriteToLine() unless it was declared in "$sText" what line to insert/overwrite. _FileWriteToLine($ifile,$random,$sText,1) @chacoya121 I tried it this way: #include <File.au3> HotKeySet("{Esc}", "_exit") HotKeySet("{Home}","Start") Global $ifile = @ScriptDir & "\text1.txt" $random = Random(1,10,1) $line = FileReadLine($ifile,$random) $sText = "my replacement line" ; Line to add/overwrite MsgBox("","","This line will be removed:"&@CRLF &"'"&$line&"'") _FileWriteToLine($ifile,$random,$sText,1) ; If True will also overwrite the old line $countline = _FileCountLines($ifile) MsgBox("","",$countline) Func _exit() Exit EndFunc 2 hours ago, chacoya121 said: i try to overwrite the line from text but its clear all In your "_FileWriteToLine()" it was declared as "" means, your text in that line will be changed to empty line or will be cleared. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.
232showtime Posted April 15, 2017 Posted April 15, 2017 (edited) I assume your file text1.txt contains a data... #include <File.au3> HotKeySet("{Esc}", "_exit") HotKeySet("{F1}", "Start") Global $ifile = FileOpen(@ScriptDir & "\text1.txt") While 1 Sleep(100) WEnd Func Start() $random = Random(1, 10, 1) $line = FileReadLine($ifile, $random) ; $ifile = FileOpen(@ScriptDir & "\text1.txt", 2);removed because it will replace the file with empty lines $FW = _FileWriteToLine(@ScriptDir & "\text1.txt", $random, "", 1); this will randomly clear all the data inside your text1.txt because you have "" $countline = _FileCountLines(@ScriptDir & "\text1.txt") ConsoleWrite("FW2L: " & "Succes: " & $countline & @CRLF) EndFunc ;==>Start Func _exit() Exit EndFunc ;==>_exit don't forget to do error checking, this will fix your script. Edited April 15, 2017 by 232showtime ill get to that... i still need to learn and understand a lot of codes Correct answer, learn to walk before you take on that marathon.
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