Jump to content

Read checkbox state and delete txt line/file


Recommended Posts

Hi all. I made a function to read a txt file and put the the lines in checkbox. But now i need to select which checkbox is checked, open txt file, delete the line with same name and file outside with the same name and delete or hide same checkbox from the gui. And a doubt, i put this function outside the function with the gui. How can i delete the gui without have to declare the global name of the gui. Regards!

If Not _FileReadToArray($Test,$aRecords) Then
    MsgBox(262160,"Error!!", "File not found!")  
    FileChangeDir(@ScriptDir)
    Return 0
Else
    For $x = 1 to $aRecords[0]
        $X_Coord = 32 + (($x - 1) * 32)
        $Checkbox = GUICtrlCreateCheckbox($aRecords[$x], 32,$X_Coord, 273, 33)
        GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
        GUISetState()
    Next
EndIf
Link to comment
Share on other sites

How can i delete the gui without have to declare the global name of the gui. Regards!

Sorry but this part is all I understand of the post.

I think you could delete a gui from any function as long as you pass that function the handle of it.

Cant see a gui in that code either, sorry.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

look up the:

ControlCommand()

GUIDelete()

FileRead()

StringInStr()

FileDelete()

FileWrite()

ControlHide()

ControlShow()

functions in the help file

to delete the line then write a new line you would have to read the file, find the line you want with an exact match with the stringinstring, make a backup copy(optional), delete the file, write the file without using the line and adding the line into it. you should get arrays from the stringinstr() so all you have to do is:

$var = $array[1] & "new line" & @lf & $array[2]

im not sure if it would work though, it may pick up the line earlier then when you want it to.

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

Link to comment
Share on other sites

Thanks pieeater. But now i can´t detect which Checkbox is checked. I try this code, but it will run once and i have to close and open the form again to select another checkbox. And i can´t delete the first checkbox. Thanks!

Function to create checkbox: 
For $x = 1 to $aRecords[0]
 $X_Coord = 32 + (($x - 1) * 32)
 $Checkbox = GUICtrlCreateCheckbox($aRecords[$x], 32,$X_Coord, 273, 33)
 GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
 GUISetState()
Next

Function to check state of checkbox above:

Func _IsChecked($sTitle, $iCtrlID)
    Return ControlCommand($sTitle, "", $iCtrlID, "IsChecked")
EndFunc



Function to select checkbox and delete line from txt file:

If _IsChecked(Form1, $Checkbox) Then
  $j = _FileCountLines("test.txt")
  For $I = 1 To $j
 _FileReadToArray("test.txt", $aFile)
 $iline = _ArraySearch($aFile,_GUICtrlButton_GetText($Checkbox), 1, $aFile[0], 1, 0, 1)
  _FileWriteToLine("test.txt", $iline, "",1)
   ControlHide(Form1, "", $Checkbox)
  Next
Else
  ConsoleWrite(">Check box #" & $Checkbox & " is unchecked" & @CRLF)
EndIf

Edited by fxg4758
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...