Jump to content
galan2015

My problem with _FileWriteToLine

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Melba23

galan2015,

Re-read the help file for _FileWriteToLine and pay particular attention to the $bOverWrite parameter.

M23

  • Like 1

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
galan2015

 

$Combo5 = GUICtrlCreateCombo("http://craigslist.org|http://reddit.com|http://google.com|http://gmail.com", 184, 98, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))

Func ZapisywanieMiejscaProgramu()
            $1ReadCombo = GUICtrlRead($Combo5)
        If $1ReadCombo = 'http://craigslist.org' then
            _FileWriteToLine(@ScriptDir&'\cfg\ostatniedane.txt',2,'1',1)
            Msgbox(1,1,$1ReadCombo)
            ElseIf $combo5 = 'http://reddit.com' then
            _FileWriteToLine(@ScriptDir&'\cfg\ostatniedane.txt',2,'2',1)
            Msgbox(1,1,$Combo5)
            ElseIf $1ReadCombo = 'http://google.com' then
            _FileWriteToLine(@ScriptDir&'\cfg\ostatniedane.txt',2,'3',1)
EndIf
EndFunc

 

_FileWriteToLine works only for first example.

Edited by galan2015

Share this post


Link to post
Share on other sites
BrewManNH

What error if any is returned by _FileWriteToLine when you use it and it doesn't work?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
galan2015

What error if any is returned by _FileWriteToLine when you use it and it doesn't work?

​Nothing showing up. :S

Share this post


Link to post
Share on other sites
Melba23

galan2015,

You have discovered a bug in _FileWriteToLine - when it was rewritten the check for an error in the $bOverWrite parameter was badly formatted and so it fails regardless of the setting. I will fix it for the next release but you can use this modified function in the meantime:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <ComboConstants.au3>
#include <File.au3>

$sFilePath = @ScriptDir & '\ostatniedane.txt'

; Simulate creation of the file
FileDelete($sFilePath)
FileWrite($sFilePath, "Fixed" & @CRLF & "Replaceable")
$sCheck = FileRead($sFilePath)
MsgBox($MB_SYSTEMMODAL, "Content", $sCheck)

$hGUI = GUICreate("Test", 500, 500)
$Combo5 = GUICtrlCreateCombo("", 184, 98, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData($Combo5, "http://craigslist.org|http://reddit.com|http://google.com|http://gmail.com")

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Combo5
            ZapisywanieMiejscaProgramu()
    EndSwitch



WEnd



Func ZapisywanieMiejscaProgramu()
    Switch GUICtrlRead($Combo5)
        Case 'http://craigslist.org'
            _FileWriteToLine_Mod($sFilePath, 2, '1', True)
        Case 'http://reddit.com'
            _FileWriteToLine_Mod($sFilePath, 2, '2', True)
        Case 'http://google.com'
            _FileWriteToLine_Mod($sFilePath, 2, '3', True)
    EndSwitch



    $sCheck = FileRead($sFilePath)
    MsgBox($MB_SYSTEMMODAL, "Content", $sCheck)

EndFunc   ;==>ZapisywanieMiejscaProgramu



Func _FileWriteToLine_Mod($sFilePath, $iLine, $sText, $bOverWrite = False)
    If $iLine <= 0 Then Return SetError(4, 0, 0)
    If Not IsString($sText) Then
        $sText = String($sText)
        If $sText = "" Then Return SetError(6, 0, 0)
    EndIf

    If $bOverWrite = Default Then $bOverWrite = False
    If Not (IsBool($bOverWrite) Or $bOverWrite = 0 Or $bOverWrite = 1) Then Return SetError(5, 0, 0) ; For old versions.
    If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)

    Local $aArray = FileReadToArray($sFilePath)
    Local $iUBound = UBound($aArray) - 1
    If ($iUBound + 1) < $iLine Then Return SetError(1, 0, 0)

    Local $hFileOpen = FileOpen($sFilePath, FileGetEncoding($sFilePath) + $FO_OVERWRITE)
    If $hFileOpen = -1 Then Return SetError(3, 0, 0)

    Local $sData = ""
    $iLine -= 1 ; Now the array is 0-based, so reduce the line number by 1.
    For $i = 0 To $iUBound
        If $i = $iLine Then
            If $bOverWrite Then
                If $sText Then $sData &= $sText & @CRLF
            Else
                $sData &= $sText & @CRLF & $aArray[$i] & @CRLF
            EndIf
        ElseIf $i < $iUBound Then
            $sData &= $aArray[$i] & @CRLF
        ElseIf $i = $iUBound Then
            $sData &= $aArray[$i]
        EndIf
    Next

    FileWrite($hFileOpen, $sData)
    FileClose($hFileOpen)
    Return 1
EndFunc   ;==>_FileWriteToLine

That works for me.

M23

Edit: Fixed.

Edited by Melba23
  • Like 1

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

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

    • chacoya121
      By chacoya121
      #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
    • 232showtime
      By 232showtime
      im getting strange output in array display,$split_[1] is not properly aligned to other arrays and why guictrlsetdata is not writting any data if i put comma(,) at the end of the text in $Input1???
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #Region ### START Koda GUI section ### Form=C:\Users\user\Desktop\Script\StringSplit.kxf $Form1 = GUICreate("Form1", 623, 449, 192, 114) $Input1 = GUICtrlCreateInput("50UGITQ421X, 50UGITQ422X, 50UGITQ423X, 50UGITQ427X, 50UGITQ431X, 50UGITQ435X, 50UGITQ436X, 50UGITQ437X, 50UGITQ441X, 50UGITQ445X, 50UGITQ449X, 50UGITQ453X, 50UGITQ454X, 50UGITQ455X, 50UGITQ459X", 24, 16, 553, 21) $Split = GUICtrlCreateButton("Split", 24, 48, 75, 25) $List1 = GUICtrlCreateList("", 24, 96, 553, 97) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Split $read = GUICtrlRead($Input1) $split_ = StringSplit($read, ",") $Max = UBound($split_, 1) For $i = 1 To UBound($split_) - 1 ConsoleWrite($split_[$i] & @CRLF) ;~ ControlSetText($Form1, "", $List1, $split_[$i]) GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $split_[$i]) ;~ GUICtrlSetData($List1, $i) Next _ArrayDisplay($split_) EndSwitch WEnd  
    • kitoy
      By kitoy
      I wanted to make a countdown timer without queueing the countdown message to the next line but the previous data is removed after using GUICtrlSetData. Any thoughts on how to display the previous data/message?

      Here is an example:
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $_main = GUICreate("", 501, 313, -1, -1) Global $g_idMemo = GUICtrlCreateEdit("", 2, 2, 496, 274, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL) GUICtrlSetData(-1, "") GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0) GUICtrlSetBkColor($g_idMemo, 0xFFFFFF) GUICtrlSetCursor($g_idMemo, -1) GUISetState(@SW_SHOW) HotKeySet('{esc}', "_close") Func _close() Exit EndFunc ;==>_close Func MemoWrite($sMessage = "") GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite MemoWrite("test message 1") Sleep(1000) MemoWrite("test message 2") Sleep(1000) MemoWrite("test message 3") Sleep(1000) For $i = 5 to 0 Step -1 GUICtrlSetData($g_idMemo, "Program will exit in "&$i&" seconds...") Sleep(1000) Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
    • kashamalasha
      By kashamalasha
      Hello.
      Could you help me find the answer for my issue. I'm trying to set fomatted data wich is selected from SQL to GUICtrlCreateEdit field.
      And the GUICtrlSetData function is inserting it in one line. But when I'm trying to do the same using MsgBox the data looks fine.
      I'm trying to not use _GUICtrlRichEdit UDF.
      Thanks in advance. Here is my test code.
      #include <GUIConstants.au3> #include <GUIListBox.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt("GUIOnEventMode", 1) $hMainGUI = GUICreate("Test", 520, 240) $hListBox = _GUICtrlListBox_Create($hMainGUI, "", 10, 10, 180, 80) $hEdit = GUICtrlCreateEdit("", 10, 80, 500, 150) GUISetState(@SW_SHOW, $hMainGUI) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") Local $hQuery, $aRow _SQLite_Startup() $hDB = _SQLite_Open('MyDB.sqlite') _SQLite_Query(-1, "SELECT ID ||"". "" || Name FROM Templates ORDER BY ID;", $hQuery) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK _GUICtrlListBox_AddString($hListBox, $aRow[0]) WEnd GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE_Button") While 1 Sleep(100) WEnd Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hListBox, $hWndListBox Switch $iCode Case $LBN_DBLCLK Select_Template(_GUICtrlListBox_GetCurSel($hListBox) + 1) Return 0 EndSwitch EndSwitch EndFunc ;==>_WM_COMMAND Func CLOSE_Button() _SQLite_Close() _SQLite_Shutdown() Exit EndFunc ;==>CLOSE_Button Func Select_Template($sListItem) _SQLite_QuerySingleRow($hDB, _ "SELECT Content " & _ "FROM Templates " & _ "WHERE ID = " & $sListItem & ";", $aRow) ;~ MsgBox(64, "Test: " & $sListItem, $aRow[0]) GUICtrlSetData($hEdit, $aRow[0]) WinSetTitle($hMainGUI, "", "Test: " & $sListItem) EndFunc ;==>Select_Template  


    • Reizvoller
      By Reizvoller
      Hello!
      When utilizing GUICtrlSetData to edit what is displayed in a GUICtrlCreateEdit field, is there a way to just make it write new lines rather than clearing what's there and writing the new information?
      For example ... 
      GUICtrlSetData ($editField, "Line one"&@CRLF , "") GUICtrlSetData ($editField, "Line two"&@CRLF , "") GUICtrlSetData ($editField, "Line three"&@CRLF , "") What happens now if those three things run one after another, the Edit field displays "Line One" , then that is replaced with "Line Two" and so on with the previous information disappearing and the subsequent taking its place. I'd like for it to say all three, one after another. Any documents on how I may accomplish this?
      Thanks!
      -Reiz
×