Jump to content

removing item from a list


Bert
 Share

Recommended Posts

I have a text file that I use to create a list. (using GUICtrlCreateCombo). Does anyone knowa way that will remove a item from the file so when the list is refreshed, the item is no longer listed? I like it so the GUI would have a remove button, and a second GUI would open that lets me choose what I want to remove. Any thoughts?

Link to comment
Share on other sites

Here is what I got so far. I'm still designing it, so the code is quite crude, and the formatting is a mess, but you will get the idea of what I'm doing.

;#NoTrayIcon
Break(0)
#include <GuiConstants.au3>
;-----------------------------
$Shandle = fileopen ("quicktext.ini", 0)
$note1 = FileReadLine ("quicktext.ini")
GUICreate("QuickText", 600, 65)
$Combo_2 = GuiCtrlCreateCombo("", 20, 5, 500, 80)
GuiCtrlSetData($combo_2, $note1)
fileclose($Shandle)
$button1 = GuiCtrlCreateButton("Paste", 530, 5, 60, 20)
$button2 = GuiCtrlCreateButton("Cancel", 530, 32, 60, 20)
$button3 = GuiCtrlCreateButton("Add", 20, 32, 60, 20)
$button4 = GuiCtrlCreateButton("Remove", 100, 32, 60, 20)
$button5 = GuiCtrlCreateButton("About", 180, 32, 60, 20)
; Run the GUI until it is closed
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
   ;When button1 is pressed, label text is copied to the clipboard
    Case $msg = $button1
      $data = GUICtrlRead($Combo_2)
      ClipPut($data)
      sleep(200)
      exit
   ;When button2 is pressed, it will open a add text box.
    Case $msg = $button2
         exit
   ;---------------------------------------
   ;this will open a sub GUI window to allow for adding or removing data
    Case $msg = $button3
      GUiDelete()
      GUICreate("Add data to QuickText", 520,65, @DesktopWidth/2-160, @DesktopHeight/2-45, -1, 0x00000018); WS_EX_ACCEPTFILES
      $file = GUICtrlCreateInput ( "", 10,  5, 500, 20)
      GUICtrlSetState(-1,$GUI_ACCEPTFILES)
      $button6 = GUICtrlCreateButton ("Ok", 10,30,60,20)
      $button7 = GUICtrlCreateButton ("Cancel", 90,30,60,20)
      GUISetState () 

      $msg = 0
        While $msg <> $GUI_EVENT_CLOSE
              $msg = GUIGetMsg()
        Select
              Case $msg = $button6; this will add data to the quicktest.ini file. It will make the file if it is missing
                   $adddata = GUICtrlRead($file)
                   $file1 = FileOpen("quicktext.ini", 1)
                   filewrite($file1, $adddata)
                   filewrite($file1, "|")
                   GUiDelete()  
                   exitloop 
                                            
              Case $msg = $button7           
                   GUiDelete()
                   exitloop
         EndSelect
 
              
         
Wend

EndSelect
      

WEnd
Exit
Link to comment
Share on other sites

I also have a second problem. When I open the "add data to quicktext" window, I have the main window close. My thinking is I need for it to be refreshed after I make my change to the ini file. The problem is the window won't reopen, no matter what I do. I know I can't do a goto statement, but in this case it would be a easy fix. What do I do? I tried to make a loop, but it doesn't work.

Edited by vollyman
Link to comment
Share on other sites

I also have a second problem. When I open the "add data to quicktext" window, I have the main window close. My thinking is I need for it to be refreshed after I make my change to the ini file. The problem is the window won't reopen, no matter what I do. I know I can't do a goto statement, but in this case it would be a easy fix. What do I do? I tried to make a loop, but it doesn't work.

Instead of GuiDelete, try GuiSetState(@SW_HIDE,$main_gui), then when done, just do GuiSetState(@SW_SHOW,$main_gui)

you need to set $main_gui when you do the initial GuiCreate.

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

just before you show it again just do

$Shandle = fileopen ("quicktext.ini", 0)

$note1 = FileReadLine ($Shandle)

fileclose($Shandle)

GuiCtrlSetData($combo_2, "|" & $note1)

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I'm not following you. What you are saying then is to do this:?

$adddata = GUICtrlRead($file)
                   $file1 = FileOpen("quicktext.ini", 1)
                   filewrite($file1, $adddata)
                   filewrite($file1, "|")
$Shandle = fileopen ("quicktext.ini", 0)
$note1 = FileReadLine ($Shandle)

fileclose($Shandle)


GuiCtrlSetData($combo_2, "|" & $note1)

this doesn't make sense. The file is already open.

Link to comment
Share on other sites

I'm not following you. What you are saying then is to do this:?

$adddata = GUICtrlRead($file)
                   $file1 = FileOpen("quicktext.ini", 1)
                   filewrite($file1, $adddata)
                   filewrite($file1, "|")
$Shandle = fileopen ("quicktext.ini", 0)
$note1 = FileReadLine ($Shandle)

fileclose($Shandle)


GuiCtrlSetData($combo_2, "|" & $note1)

this doesn't make sense. The file is already open.

it does make sense, being you have it open in write mode, you'll need to close it first

$adddata = GUICtrlRead($file)
                   $file1 = FileOpen($file, 1)
                   filewrite($file1, $adddata & "|")
                   FileClose($file1)


$Shandle = fileopen ("quicktext.ini", 0)
$note1 = FileReadLine ($Shandle)

fileclose($Shandle)


GuiCtrlSetData($combo_2, "|" & $note1)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

;#NoTrayIcon
Break(0)
#include <GuiConstants.au3>
;-----------------------------
$main_gui = GUICreate("QuickText", 600, 65)
$Combo_2 = GUICtrlCreateCombo("", 20, 5, 500, 80)
_LoadData(@ScriptDir & "\quicktext.ini", $Combo_2)
$button1 = GUICtrlCreateButton("Paste", 530, 5, 60, 20)
$button2 = GUICtrlCreateButton("Cancel", 530, 32, 60, 20)
$button3 = GUICtrlCreateButton("Add", 20, 32, 60, 20)
$button4 = GUICtrlCreateButton("Remove", 100, 32, 60, 20)
$button5 = GUICtrlCreateButton("About", 180, 32, 60, 20)
; Run the GUI until it is closed
GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
        ;When button1 is pressed, label text is copied to the clipboard
      Case $msg = $button1
         $data = GUICtrlRead($Combo_2)
         ClipPut($data)
         Sleep(200)
         Exit
        ;When button2 is pressed, it will open a add text box.
      Case $msg = $button2
         Exit
        ;---------------------------------------
        ;this will open a sub GUI window to allow for adding or removing data
      Case $msg = $button3
         GUISetState(@SW_HIDE, $main_gui)
         $add_gui = GUICreate("Add data to QuickText", 520, 65, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
         $file = GUICtrlCreateInput("", 10, 5, 500, 20)
         GUICtrlSetState(-1, $GUI_ACCEPTFILES)
         $button6 = GUICtrlCreateButton("Ok", 10, 30, 60, 20)
         $button7 = GUICtrlCreateButton("Cancel", 90, 30, 60, 20)
         GUISetState(@SW_SHOW, $add_gui)
         
         $msg = 0
         While $msg <> $GUI_EVENT_CLOSE
            $msg = GUIGetMsg()
            Select
               Case $msg = $button6; this will add data to the quicktest.ini file. It will make the file if it is missing
                  $adddata = GUICtrlRead($file)
                  $file1 = FileOpen("quicktext.ini", 1)
                  FileWrite($file1, $adddata & "|")
                        FileClose($file1)
                  GUIDelete($add_gui)
                  ExitLoop
                  
               Case $msg = $button7
                  GUIDelete($add_gui)
                  
                  ExitLoop
            EndSelect
            
            
            
         WEnd
         _LoadData(@ScriptDir & "\quicktext.ini", $Combo_2)
         GUISetState(@SW_SHOW, $main_gui)
   EndSelect
   
   
WEnd
Exit

Func _LoadData($s_file, ByRef $h_Combo)
   $Shandle = FileOpen($s_file, 0)
   $note1 = FileReadLine($Shandle)
   FileClose($Shandle)
   GUICtrlSetData($h_Combo, "|" & $note1)
EndFunc  ;==>_LoadData

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

where do I drop it in? I tried to put it in as a Case, but I get a wend error.

This is what I did using the code in this forum.

;#NoTrayIcon
#include <GuiConstants.au3>
#include <File.au3>
;-----------------------------
$main_gui = GUICreate("QuickText", 600, 65)
$Combo_2 = GUICtrlCreateCombo("", 20, 5, 500, 80)
_LoadData(@ScriptDir & "\quicktext.ini", $Combo_2)
$button1 = GUICtrlCreateButton("Paste", 530, 5, 60, 20)
$button2 = GUICtrlCreateButton("Cancel", 530, 32, 60, 20)
$button3 = GUICtrlCreateButton("Add", 20, 32, 60, 20)
$button4 = GUICtrlCreateButton("Remove", 100, 32, 60, 20)
$button5 = GUICtrlCreateButton("About", 180, 32, 60, 20)
; Run the GUI until it is closed
GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      ;When button1 is pressed, label text is copied to the clipboard
      Case $msg = $button1
         $data = GUICtrlRead($Combo_2)
         ClipPut($data)
         Sleep(200)
         Exit
      ;When button2 is pressed, it will open a add text box.
      Case $msg = $button2
         Exit
      ;---------------------------------------
      ;this will open a sub GUI window to allow for adding or removing data
      Case $msg = $button3
         GUISetState(@SW_HIDE, $main_gui)
         $add_gui = GUICreate("Add data to QuickText", 520, 65, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES
         $file = GUICtrlCreateInput("", 10, 5, 500, 20)
         GUICtrlSetState(-1, $GUI_ACCEPTFILES)
         $button6 = GUICtrlCreateButton("Ok", 10, 30, 60, 20)
         $button7 = GUICtrlCreateButton("Cancel", 90, 30, 60, 20)
         GUISetState(@SW_SHOW, $add_gui)
         $msg = 0
         While $msg <> $GUI_EVENT_CLOSE
            $msg = GUIGetMsg()
            Select
               Case $msg = $button6; this will add data to the quicktest.ini file. It will make the file if it is missing
                  $adddata = GUICtrlRead($file)
                  $file1 = FileOpen("quicktext.ini", 1)
                  FileWrite($file1, $adddata & "|")
                        FileClose($file1)
                  GUIDelete($add_gui)
                  ExitLoop
                  
               Case $msg = $button7
                  GUIDelete($add_gui)
                  
                  ExitLoop

            EndSelect
            
            
            
         WEnd
         _LoadData(@ScriptDir & "\quicktext.ini", $Combo_2)
         GUISetState(@SW_SHOW, $main_gui)
[b];---------put it here------>
     Case $msg = $button4
         _RemoveData()
;---------put it here------>[/b]
   EndSelect

  
WEnd
Exit

Func _LoadData($s_file, ByRef $h_Combo)
   $Shandle = FileOpen($s_file, 0)
   $note1 = FileReadLine($Shandle)
   FileClose($Shandle)
   GUICtrlSetData($h_Combo, "|" & $note1)
EndFunc;==>_LoadData

Func _RemoveData()
    $xData = GUICtrlRead($Combo_2)
    MsgBox(32,"removing","Remove " & $xData & " from quicktext.ini")
    _ReplaceStringInFile("quicktext.ini",$xData & "|","")
    _LoadData(@ScriptDir & "\quicktext.ini", $Combo_2)
EndFunc
Edited by kpu
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...