# plz help with _filewritetoline

## Recommended Posts

#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 by Melba23

##### Share on other sites

@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.

chacoya121,

_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 #### Share this post ##### Link to post ##### Share on other sites 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._______My UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columns ChooseFileFolder ---- Single and multiple selections from specified path treeview listing Date_Time_Convert -- Easily convert date/time formats, including the language used ExtMsgBox --------- A highly customisable replacement for MsgBox GUIExtender -------- Extend and retract multiple sections within a GUI GUIFrame ---------- Subdivide GUIs into many adjustable frames GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView Marquee ----------- Scrolling tickertape GUIs NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes Notify ------------- Small notifications on the edge of the display Scrollbars ----------Automatically sized scrollbars with a single command StringSize ---------- Automatically size controls to fit text Toast -------------- Small GUIs which pop out of the notification area #### Share this post ##### Link to post ##### Share on other sites @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. #### Share this post ##### Link to post ##### Share on other sites 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 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. #### Share this post ##### Link to post ##### Share on other sites ## 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 account ## Sign in Already have an account? Sign in here. Sign In Now • ### Similar Content • By galan2015 Case$Combo4; Stany $ReadCombo = GUICtrlRead($Combo4) if $ReadCombo = "California" then$ReadFile = FileRead(@ScriptDir&'\Dzielnice\California.txt') GUICtrlSetData($Combo5,$ReadFile) _FileWriteToLine(@ScriptDir&'\cfg\ostatniedane.txt',1,'5') I want overwrite the First line of file ostatniedane.txt but it's only adds another one :/ Anyone Could help me?
• By LetsAuto
Hi everyone.. not quite sure how to get a list box to save its strings into a single .log or .txt file (either would work for me), and then later call each individual string..
the list box has up to 30 items in it, the user will be able to deselect certain items, or select items... i just need a way to save each string into an external file so i can later call them back as variables and display them into a disabled list box.. if anyone could help that would be extremely appreciated. reply if my objective is confusing.
THANKS!
×

• Wiki

• Back

• Git