Jump to content

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
Added code tags
Link to comment
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.

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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.

Link to comment
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 graduated.gif

Correct answer, learn to walk before you take on that marathon.

Link to comment
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
 Share

×
×
  • Create New...