incepator Posted February 3, 2013 Share Posted February 3, 2013 hello I have a problem. I made this script, working with dynamic variables, I I can not figure out how to use$Itemnew expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) $MenuItem1 = GUICtrlCreateMenu("File") $MenuItem2 = GUICtrlCreateMenuItem("Add Keywords", $MenuItem1) $MenuItem3 = GUICtrlCreateMenu("Recent files", $MenuItem1) $MenuItem5 = GUICtrlCreateMenuItem("Clear List Recent", $MenuItem1) $MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem1) GUISetState(@SW_SHOW) If FileExists(@ScriptDir&"\"&"recently.txt") Then $total_lines = _FileCountLines(@ScriptDir&"\"&"recently.txt") $read_file = FileOpen(@ScriptDir&"\"&"recently.txt", 0) For $firstline = 1 To $total_lines Global $Itemnew = GUICtrlCreateMenuItem(FileReadLine($read_file, $firstline), $MenuItem3) Next FileClose($read_file) Else $write = FileOpen(@ScriptDir&"\"&"recently.txt", 1) FileClose($write) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $MenuItem6 Exit Case $MenuItem5 FileDelete(@ScriptDir&"\"&"recently.txt") GUICtrlDelete($MenuItem3) GUICtrlCreateMenu("Recent Files", $MenuItem1, 1) Case $MenuItem2 $open_file = FileOpenDialog("Add Keywords List", @ScriptDir& "\", "Txt (*.txt)", 1) If Not @error Then $write2 = FileOpen(@ScriptDir&"\"&"recently.txt", 1) FileWriteLine($write2,$open_file) FileClose($write2) GUICtrlCreateMenuItem($open_file, $MenuItem3) EndIf ;Case $Itemnew ;MsgBox(0,"test",GUICtrlRead($Itemnew)) EndSwitch WEnd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2013 Moderators Share Posted February 3, 2013 (edited) incepator, I would do it like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> Global $aRecent, $aMenu_CID[1] = [0] $sRecent = @ScriptDir & "\recently.txt" $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Menu1 = GUICtrlCreateMenu("File") $MenuItem2 = GUICtrlCreateMenuItem("Add Keywords", $Menu1) $Menu2 = GUICtrlCreateMenu("Recent files", $Menu1) $MenuItem5 = GUICtrlCreateMenuItem("Clear List Recent", $Menu1) $MenuItem6 = GUICtrlCreateMenuItem("Exit", $Menu1) GUISetState(@SW_SHOW) If FileExists($sRecent) Then _FileReadToArray($sRecent, $aRecent) If IsArray($aRecent) Then For $i = 1 To $aRecent[0] $aMenu_CID[0] += 1 ReDim $aMenu_CID[$aMenu_CID[0] + 1] $aMenu_CID[$aMenu_CID[0]] = GUICtrlCreateMenuItem($aRecent[$i], $Menu2) Next EndIf Else $write = FileOpen($sRecent, 1) FileClose($write) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $MenuItem6 Exit Case $MenuItem5 $write = FileOpen($sRecent, 2) FileClose($write) GUICtrlDelete($Menu2) $Menu2 = GUICtrlCreateMenu("Recent Files", $Menu1, 1) Global $aMenu_CID[1] = [0] Case $MenuItem2 $open_file = FileOpenDialog("Add Keywords List", @ScriptDir & "\", "Txt (*.*)", 1) If Not @error Then $write = FileOpen($sRecent, 1) FileWriteLine($write, @CRLF & $open_file) FileClose($write) $aMenu_CID[0] += 1 ReDim $aMenu_CID[$aMenu_CID[0] + 1] $aMenu_CID[$aMenu_CID[0]] = GUICtrlCreateMenuItem($open_file, $Menu2) EndIf Case Else For $i = 1 To $aMenu_CID[0] If $nMsg = $aMenu_CID[$i] Then $sText = GUICtrlRead($aMenu_CID[$i], 1) ConsoleWrite($sText & @CRLF) ExitLoop EndIf Next EndSwitch WEnd Any questions? M23 Edited February 3, 2013 by Melba23 Typo incepator 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
incepator Posted February 3, 2013 Author Share Posted February 3, 2013 oh ... very well done, I will try to learn from your examples, thanks! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2013 Moderators Share Posted February 3, 2013 (edited) incepator, There was a typo in the code - you need to download the new version above. M23 Edited February 3, 2013 by Melba23 Need a new keyboard or new fingers! 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
incepator Posted February 3, 2013 Author Share Posted February 3, 2013 I want to do something to add if the file is not duplicated in Recent Files Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2013 Moderators Share Posted February 3, 2013 (edited) incepator,I want to do something...So what is stopping you? Or do you mean "I want you to do something"? M23Edit: My version is all done - any sign of yours? Edited February 3, 2013 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
incepator Posted February 3, 2013 Author Share Posted February 3, 2013 I tried to get rid of duplicates in this way: $op = FileOpen($sRecent, 0) $read = FileRead($op) If Not @error Then If StringInStr($read, $open_file) Then $aMenu_CID[$aMenu_CID[0]] = GUICtrlCreateMenuItem($open_file, $MenuItem2_1) EndIf EndIf but it does not work that way, I think it is the other way.. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2013 Moderators Share Posted February 3, 2013 incepator, I did it this way: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> Global $aRecent, $aMenu_CID[1][2] = [[0]] ; 2D array to hold both CID and text <<<<<<<<<<<<<<<<< $sRecent = @ScriptDir & "\recently.txt" $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Menu1 = GUICtrlCreateMenu("File") $MenuItem2 = GUICtrlCreateMenuItem("Add Keywords", $Menu1) $Menu2 = GUICtrlCreateMenu("Recent files", $Menu1) $MenuItem5 = GUICtrlCreateMenuItem("Clear List Recent", $Menu1) $MenuItem6 = GUICtrlCreateMenuItem("Exit", $Menu1) GUISetState(@SW_SHOW) If FileExists($sRecent) Then _FileReadToArray($sRecent, $aRecent) If IsArray($aRecent) Then For $i = 1 To $aRecent[0] $aMenu_CID[0][0] += 1 ReDim $aMenu_CID[$aMenu_CID[0][0] + 1][2] $aMenu_CID[$aMenu_CID[0][0]][0] = GUICtrlCreateMenuItem($aRecent[$i], $Menu2) $aMenu_CID[$aMenu_CID[0][0]][1] = $aRecent[$i] Next EndIf Else $write = FileOpen($sRecent, 1) FileClose($write) EndIf While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $MenuItem6 Exit Case $MenuItem5 $write = FileOpen($sRecent, 2) FileClose($write) GUICtrlDelete($Menu2) $Menu2 = GUICtrlCreateMenu("Recent Files", $Menu1, 1) Global $aMenu_CID[1][2] = [[0]] Case $MenuItem2 $open_file = FileOpenDialog("Add Keywords List", @ScriptDir & "\", "Txt (*.*)", 1) If Not @error And _ArraySearch($aMenu_CID, $open_file, 1, 0, 0, 0, 1, 1) = -1 Then ; Search array to see if it exists already <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $write = FileOpen($sRecent, 1) FileWriteLine($write, @CRLF & $open_file) FileClose($write) $aMenu_CID[0][0] += 1 ReDim $aMenu_CID[$aMenu_CID[0][0] + 1][2] $aMenu_CID[$aMenu_CID[0][0]][0] = GUICtrlCreateMenuItem($open_file, $Menu2) $aMenu_CID[$aMenu_CID[0][0]][1] = $open_file EndIf Case Else For $i = 1 To $aMenu_CID[0][0] If $nMsg = $aMenu_CID[$i][0] Then $sText = $aMenu_CID[$i][1] ConsoleWrite($sText & @CRLF) ExitLoop EndIf Next EndSwitch WEnd M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
incepator Posted February 3, 2013 Author Share Posted February 3, 2013 indeed working properly at the moment is too complicated for me to understand this script. in time I'll understand. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2013 Moderators Share Posted February 3, 2013 incepator,at the moment is too complicated for me to understandThen ask questions as I suggested - otherwise you will never learn. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now