Jump to content

Function acting up


Naufuge
 Share

Recommended Posts

I think my logic is right, but could someone look over this.

Func File_Delete()
    $Selected_Setting = GuiCtrlRead($Setting_List)
    $Selected_Setting = $Selected_Setting - 30
        If $Selected_Setting = -30 Then
            MsgBox(48,"Gui Error - Delete","No Setting Selected, please Select a Setting then try again.")
        Else
            $Read_Line = 1
            $Line_Count = _FileCountLines(@ScriptDir & "\Configuration Files\Settings.dbl")
            If @Error = 1 Then
                MsgBox(48,"Gui Error - Delete","Setting File could not be opened.  Please try again.")
            Else
            Do
                If $Read_Line = $Selected_Setting Then
                Else
                    $Stored_Line = FileReadLine(@ScriptDir & "\Configuration Files\Settings.dbl",$Read_Line)
                    If $Stored_Line = "" Then
                    Else
                        FileWriteLine(@ScriptDir & "\Configuration Files\Temp_Settings.dbl",$Stored_Line)
                    EndIf
                EndIf
                $Read_Line = $Read_Line + 1
            Until $Read_Line = $Line_Count
            EndIf
        FileDelete(@ScriptDir & "\Configuration Files\Settings.dbl")
        FileCopy(@ScriptDir & "\Configuration Files\Temp_Settings.dbl",@ScriptDir & "\Configuration Files\Settings.dbl")
        FileDelete(@ScriptDir & "\Configuration Files\Temp_Settings.dbl")
        FileWrite(@ScriptDir & "\Configuration Files\Temp_Settings.dbl","")
        EndIf
    Update_SettingList()
EndFunc

This is one of the functions from my program, that stores which item is selected in a List, then compares it to which line it is in a txt file, and if they are equal it deletes the line from the txt file. But if you select the first line of the list, it deletes every line of the txt file for some reason, can someone with more knowledge look at this for me.

Thank you

Link to comment
Share on other sites

Keep in mind that I still new at AutoIt but I believe that when you used this line:

$Selected_Setting = GuiCtrlRead($Setting_List) it return the string and not a number so, when you subtract 30 $Selected_Setting is always -30. In some of my script I have different behavor usign IF statement, when you used If $Selected_Setting = -30 with single = than when I used If $Selected_Setting == -30 with double ==, I could be wrong but I think when you used if with single = it assing that value to the variable and if you use if with double == it compare the varible. Also in case that you didn't know when using an IF statement this <> mean NOT EQUAL.

It is kind of hard to help you without the rest of the script but, I did some changes to your function and only works if your listbox is set for a single selection.

#include <GuiList.au3>

Func File_Delete()
    $Selected_Setting = _GUICtrlListSelectedIndex($Setting_List)
    If $Selected_Setting == $LB_ERR Then
        MsgBox(48,"Gui Error - Delete","No Setting Selected, please Select a Setting then try again.")
        Return(1);meaning no setting selected
    Else
        $Read_Line = 1
        $Line_Count = _FileCountLines(@ScriptDir & "\Configuration Files\Settings.dbl")
        If @Error Then
            MsgBox(48,"Gui Error - Delete","Setting File could not be opened.  Please try again.")
            Return(2);meaning setting file could not be open
        Else
            Do
                If $Read_Line <> $Selected_Setting Then
                    $Stored_Line = FileReadLine(@ScriptDir & "\Configuration Files\Settings.dbl", $Read_Line)
                    If $Stored_Line <> "" Then FileWriteLine(@ScriptDir & "\Configuration Files\Temp_Settings.dbl",$Stored_Line)                
                EndIf
                $Read_Line = $Read_Line + 1
            Until $Read_Line = $Line_Count
        EndIf
        FileDelete(@ScriptDir & "\Configuration Files\Settings.dbl")
        FileCopy(@ScriptDir & "\Configuration Files\Temp_Settings.dbl",@ScriptDir & "\Configuration Files\Settings.dbl")
        FileDelete(@ScriptDir & "\Configuration Files\Temp_Settings.dbl")
        FileWrite(@ScriptDir & "\Configuration Files\Temp_Settings.dbl","")
    EndIf
    Update_SettingList()
    Return(0);meaning everything when OK.
EndFunc
Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
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...