mikell Posted November 11, 2014 Share Posted November 11, 2014 Probably, but as said TheSaint in post #22 without appropriate indentation your code is actually confusing and very difficult to read, so it is difficult to give an answer Link to comment Share on other sites More sharing options...
Arclite86 Posted November 12, 2014 Author Share Posted November 12, 2014 Probably, but as said TheSaint in post #22 without appropriate indentation your code is actually confusing and very difficult to read, so it is difficult to give an answer How can i change it , what part of my script are are not indentation, please be more specific, so I can change that Link to comment Share on other sites More sharing options...
Solution MHz Posted November 12, 2014 Solution Share Posted November 12, 2014 I did this, it worked but sometimes it doesnt react than I have to click 3 or 4 times until the function works, is there a way It can be improved? You have a 2nd GUIGetMsg() which is having an effect on the flow of the loop. Comment that out and it works much better. I changed the conditions in the loop to use Switch..EndSwitch as some have recommended so it will work better hopefully. FileOpenDialog changes the working directory so passing @WorkingDir as a parameter to _FillLists() seems more suited then passing the selected files path and replacing Openfile.txt to get the same result. More could be improved though I do not want to change too much which may confuse you. Some use of arrays could help to shrink the code down but I am not sure of your current experience level for changing any of that. See if this helps. expandcollapse popup$_FF_COM_TRACE = True #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> ;#include <FF.au3> #include <staticConstants.au3> #include <IE.au3> #include <String.au3> #include <Excel.au3> #include <FileConstants.au3> #include <IE.au3> #include <String.au3> #include <GUIConstantsEx.au3> #include "GUIExtender.au3" #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $oIE ;, BitOR($WS_BORDER, $WS_VSCROLL) ;_FFStart( "https://www.google.nl" ) ;WinSetState ( "Google - Mozilla Firefox", "", @SW_MINIMIZE ) ;~ _GUIExtender_Init($Form1_1_1_1) FileWrite(@ScriptDir & "\Openfile.txt", "text") For $i = 1 To 13 FileDelete(@ScriptDir & "\list" & $i & ".txt") FileWrite(@ScriptDir & "\list" & $i & ".txt", "text " & $i) Next Global $iIndex = 0 #Region ### START Koda GUI section ### Form= $Form1_1_1_1 = GUICreate("program", 814, 713, 697, 101) $Button1 = GUICtrlCreateButton("Next", 208, 0, 41, 25) $List1 = GUICtrlCreateList("", 0, 64, 145, 358) GUICtrlSetData(-1, "") $List2 = GUICtrlCreateList("", 144, 64, 65, 358) GUICtrlSetData(-1, "") $List3 = GUICtrlCreateList("", 208, 64, 65, 358) GUICtrlSetData(-1, "") $List4 = GUICtrlCreateList("", 344, 64, 153, 358) GUICtrlSetData(-1, "") $List5 = GUICtrlCreateList("", 496, 64, 65, 358) GUICtrlSetData(-1, "") $List6 = GUICtrlCreateList("", 560, 64, 121, 230) GUICtrlSetData(-1, "") $List7 = GUICtrlCreateList("", 680, 64, 65, 230) GUICtrlSetData(-1, "") $List8 = GUICtrlCreateList("", 744, 64, 65, 230) GUICtrlSetData(-1, "") $List9 = GUICtrlCreateList("", 272, 64, 65, 358) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) Local $helpmenu, $infoitem, $exititem, $recentfilesmenu Local $viewmenu, $viewstatusitem Local $statuslabel, $msg, $file $filemenu = GUICtrlCreateMenu("&File") $fileitem = GUICtrlCreateMenuItem("Open", $filemenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) $newitem = GUICtrlCreateMenuItem("new", $filemenu) $helpmenu = GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlSetState(-1, $GUI_DISABLE) $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu) $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1) GUICtrlCreateMenuItem("", $filemenu, 2) ; create a separator line $viewmenu = GUICtrlCreateMenu("View", -1, 1) ; is created before "?" menu $viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu) $message4 = GUICtrlCreateMenuItem("message", $filemenu) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 $msg = GUIGetMsg() Switch $msg Case $fileitem ConsoleWrite("Hit" & @CRLF) ; Find Openfile.txt to get change the working directory to where it exists. $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)", 1, "Openfile.txt") If Not @error Then GUICtrlCreateMenuItem($file, $recentfilesmenu) ; FileOpenDialog changes the working directory to the selected files location. This is what you want? _FillLists(@WorkingDir) EndIf Case $newitem $newitem = FileSaveDialog("Choose file...", @TempDir, "All (*.*)") Case $viewstatusitem If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED) GUICtrlSetState($statuslabel, $GUI_HIDE) Else GUICtrlSetState($viewstatusitem, $GUI_CHECKED) GUICtrlSetState($statuslabel, $GUI_SHOW) EndIf Case $GUI_EVENT_CLOSE, $exititem ExitLoop Case $infoitem MsgBox($MB_SYSTEMMODAL, "Info", "Only a test...") Case $Button1 _pluseen($Button1) EndSwitch WEnd GUIDelete() #EndRegion ### END Koda GUI section ### Func _FillLists($file) ; The next 2 lines seem to be obsolete. ;~ Local $newfile = StringReplace($file, "Openfile.txt", "") ;~ $1newfile = ($newfile & ("lists\list")) ; $file will be the working directory path changed with previous use of FileOpenDialog Local $1newfile = $file & '\list' Global $iIndex = 0, $sListData1 = ($1newfile & ("1.txt")) Global $sListFile1 = ($1newfile & ("1.txt")) Global $iIndex = 0, $sListData2 = ($1newfile & ("2.txt")) Global $sListFile2 = ($1newfile & ("2.txt")) Global $iIndex = 0, $sListData3 = ($1newfile & ("3.txt")) Global $sListFile3 = ($1newfile & ("3.txt")) Global $iIndex = 0, $sListData4 = ($1newfile & ("4.txt")) Global $sListFile4 = ($1newfile & ("4.txt")) Global $iIndex = 0, $sListData5 = ($1newfile & ("5.txt")) Global $sListFile5 = ($1newfile & ("5.txt")) Global $iIndex = 0, $sListData6 = ($1newfile & ("6.txt")) Global $sListFile6 = ($1newfile & ("6.txt")) Global $iIndex = 0, $sListData7 = ($1newfile & ("7.txt")) Global $sListFile7 = ($1newfile & ("7.txt")) Global $iIndex = 0, $sListData8 = ($1newfile & ("8.txt")) Global $sListFile8 = ($1newfile & ("8.txt")) Global $iIndex = 0, $sListData9 = ($1newfile & ("9.txt")) Global $sListFile9 = ($1newfile & ("9.txt")) Global $iIndex = 0, $sListData10 = ($1newfile & ("10.txt")) Global $sListFile10 = ($1newfile & ("10.txt")) Global $iIndex = 0, $sListData11 = ($1newfile & ("11.txt")) Global $sListFile11 = ($1newfile & ("11.txt")) Global $iIndex = 0, $sListData12 = ($1newfile & ("12.txt")) Global $sListFile12 = ($1newfile & ("12.txt")) Global $iIndex = 0, $sListData13 = ($1newfile & ("13.txt")) Global $sListFile13 = ($1newfile & ("13.txt")) ; Read saved file if it exists-------- If FileExists($sListFile1) Then $sListData1 = FileRead($sListFile1) Else MsgBox($MB_SYSTEMMODAL, "Error", $sListFile1 & " does not exist") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf ; Load data read from the file GUICtrlSetData($List1, $sListData1) _GUICtrlListBox_SetCurSel($List1, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile2) Then $sListData2 = FileRead($sListFile2) EndIf ; Load data read from the file GUICtrlSetData($List2, $sListData2) _GUICtrlListBox_SetCurSel($List2, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile3) Then $sListData3 = FileRead($sListFile3) EndIf ; Load data read from the file GUICtrlSetData($List3, $sListData3) _GUICtrlListBox_SetCurSel($List3, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile4) Then $sListData4 = FileRead($sListFile4) EndIf ; Load data read from the file GUICtrlSetData($List4, $sListData4) _GUICtrlListBox_SetCurSel($List4, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile5) Then $sListData5 = FileRead($sListFile5) EndIf ; Load data read from the file GUICtrlSetData($List5, $sListData5) _GUICtrlListBox_SetCurSel($List5, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile6) Then $sListData6 = FileRead($sListFile6) EndIf ; Load data read from the file GUICtrlSetData($List6, $sListData6) _GUICtrlListBox_SetCurSel($List6, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile7) Then $sListData7 = FileRead($sListFile7) EndIf ; Load data read from the file GUICtrlSetData($List7, $sListData7) _GUICtrlListBox_SetCurSel($List7, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile8) Then $sListData8 = FileRead($sListFile8) EndIf ; Load data read from the file GUICtrlSetData($List8, $sListData8) _GUICtrlListBox_SetCurSel($List8, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile9) Then $sListData9 = FileRead($sListFile9) EndIf ; Load data read from the file GUICtrlSetData($List9, $sListData9) _GUICtrlListBox_SetCurSel($List9, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile10) Then $sListData10 = FileRead($sListFile10) EndIf EndFunc Func _pluseen($Button1) $iIndex += 1 _GUICtrlListBox_SetCurSel($List1, $iIndex) _GUICtrlListBox_SetCurSel($List4, $iIndex) EndFunc ; Link to comment Share on other sites More sharing options...
Arclite86 Posted November 12, 2014 Author Share Posted November 12, 2014 You have a 2nd GUIGetMsg() which is having an effect on the flow of the loop. Comment that out and it works much better. I changed the conditions in the loop to use Switch..EndSwitch as some have recommended so it will work better hopefully. FileOpenDialog changes the working directory so passing @WorkingDir as a parameter to _FillLists() seems more suited then passing the selected files path and replacing Openfile.txt to get the same result. More could be improved though I do not want to change too much which may confuse you. Some use of arrays could help to shrink the code down but I am not sure of your current experience level for changing any of that. See if this helps. expandcollapse popup$_FF_COM_TRACE = True #include <MsgBoxConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> ;#include <FF.au3> #include <staticConstants.au3> #include <IE.au3> #include <String.au3> #include <Excel.au3> #include <FileConstants.au3> #include <IE.au3> #include <String.au3> #include <GUIConstantsEx.au3> #include "GUIExtender.au3" #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local $oIE ;, BitOR($WS_BORDER, $WS_VSCROLL) ;_FFStart( "https://www.google.nl" ) ;WinSetState ( "Google - Mozilla Firefox", "", @SW_MINIMIZE ) ;~ _GUIExtender_Init($Form1_1_1_1) FileWrite(@ScriptDir & "\Openfile.txt", "text") For $i = 1 To 13 FileDelete(@ScriptDir & "\list" & $i & ".txt") FileWrite(@ScriptDir & "\list" & $i & ".txt", "text " & $i) Next Global $iIndex = 0 #Region ### START Koda GUI section ### Form= $Form1_1_1_1 = GUICreate("program", 814, 713, 697, 101) $Button1 = GUICtrlCreateButton("Next", 208, 0, 41, 25) $List1 = GUICtrlCreateList("", 0, 64, 145, 358) GUICtrlSetData(-1, "") $List2 = GUICtrlCreateList("", 144, 64, 65, 358) GUICtrlSetData(-1, "") $List3 = GUICtrlCreateList("", 208, 64, 65, 358) GUICtrlSetData(-1, "") $List4 = GUICtrlCreateList("", 344, 64, 153, 358) GUICtrlSetData(-1, "") $List5 = GUICtrlCreateList("", 496, 64, 65, 358) GUICtrlSetData(-1, "") $List6 = GUICtrlCreateList("", 560, 64, 121, 230) GUICtrlSetData(-1, "") $List7 = GUICtrlCreateList("", 680, 64, 65, 230) GUICtrlSetData(-1, "") $List8 = GUICtrlCreateList("", 744, 64, 65, 230) GUICtrlSetData(-1, "") $List9 = GUICtrlCreateList("", 272, 64, 65, 358) GUICtrlSetData(-1, "") GUISetState(@SW_SHOW) Local $helpmenu, $infoitem, $exititem, $recentfilesmenu Local $viewmenu, $viewstatusitem Local $statuslabel, $msg, $file $filemenu = GUICtrlCreateMenu("&File") $fileitem = GUICtrlCreateMenuItem("Open", $filemenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) $newitem = GUICtrlCreateMenuItem("new", $filemenu) $helpmenu = GUICtrlCreateMenu("?") GUICtrlCreateMenuItem("Save", $filemenu) GUICtrlSetState(-1, $GUI_DISABLE) $infoitem = GUICtrlCreateMenuItem("Info", $helpmenu) $exititem = GUICtrlCreateMenuItem("Exit", $filemenu) $recentfilesmenu = GUICtrlCreateMenu("Recent Files", $filemenu, 1) GUICtrlCreateMenuItem("", $filemenu, 2) ; create a separator line $viewmenu = GUICtrlCreateMenu("View", -1, 1) ; is created before "?" menu $viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu) $message4 = GUICtrlCreateMenuItem("message", $filemenu) GUICtrlSetState(-1, $GUI_FOCUS) GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 $msg = GUIGetMsg() Switch $msg Case $fileitem ConsoleWrite("Hit" & @CRLF) ; Find Openfile.txt to get change the working directory to where it exists. $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)", 1, "Openfile.txt") If Not @error Then GUICtrlCreateMenuItem($file, $recentfilesmenu) ; FileOpenDialog changes the working directory to the selected files location. This is what you want? _FillLists(@WorkingDir) EndIf Case $newitem $newitem = FileSaveDialog("Choose file...", @TempDir, "All (*.*)") Case $viewstatusitem If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED) GUICtrlSetState($statuslabel, $GUI_HIDE) Else GUICtrlSetState($viewstatusitem, $GUI_CHECKED) GUICtrlSetState($statuslabel, $GUI_SHOW) EndIf Case $GUI_EVENT_CLOSE, $exititem ExitLoop Case $infoitem MsgBox($MB_SYSTEMMODAL, "Info", "Only a test...") Case $Button1 _pluseen($Button1) EndSwitch WEnd GUIDelete() #EndRegion ### END Koda GUI section ### Func _FillLists($file) ; The next 2 lines seem to be obsolete. ;~ Local $newfile = StringReplace($file, "Openfile.txt", "") ;~ $1newfile = ($newfile & ("lists\list")) ; $file will be the working directory path changed with previous use of FileOpenDialog Local $1newfile = $file & '\list' Global $iIndex = 0, $sListData1 = ($1newfile & ("1.txt")) Global $sListFile1 = ($1newfile & ("1.txt")) Global $iIndex = 0, $sListData2 = ($1newfile & ("2.txt")) Global $sListFile2 = ($1newfile & ("2.txt")) Global $iIndex = 0, $sListData3 = ($1newfile & ("3.txt")) Global $sListFile3 = ($1newfile & ("3.txt")) Global $iIndex = 0, $sListData4 = ($1newfile & ("4.txt")) Global $sListFile4 = ($1newfile & ("4.txt")) Global $iIndex = 0, $sListData5 = ($1newfile & ("5.txt")) Global $sListFile5 = ($1newfile & ("5.txt")) Global $iIndex = 0, $sListData6 = ($1newfile & ("6.txt")) Global $sListFile6 = ($1newfile & ("6.txt")) Global $iIndex = 0, $sListData7 = ($1newfile & ("7.txt")) Global $sListFile7 = ($1newfile & ("7.txt")) Global $iIndex = 0, $sListData8 = ($1newfile & ("8.txt")) Global $sListFile8 = ($1newfile & ("8.txt")) Global $iIndex = 0, $sListData9 = ($1newfile & ("9.txt")) Global $sListFile9 = ($1newfile & ("9.txt")) Global $iIndex = 0, $sListData10 = ($1newfile & ("10.txt")) Global $sListFile10 = ($1newfile & ("10.txt")) Global $iIndex = 0, $sListData11 = ($1newfile & ("11.txt")) Global $sListFile11 = ($1newfile & ("11.txt")) Global $iIndex = 0, $sListData12 = ($1newfile & ("12.txt")) Global $sListFile12 = ($1newfile & ("12.txt")) Global $iIndex = 0, $sListData13 = ($1newfile & ("13.txt")) Global $sListFile13 = ($1newfile & ("13.txt")) ; Read saved file if it exists-------- If FileExists($sListFile1) Then $sListData1 = FileRead($sListFile1) Else MsgBox($MB_SYSTEMMODAL, "Error", $sListFile1 & " does not exist") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf ; Load data read from the file GUICtrlSetData($List1, $sListData1) _GUICtrlListBox_SetCurSel($List1, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile2) Then $sListData2 = FileRead($sListFile2) EndIf ; Load data read from the file GUICtrlSetData($List2, $sListData2) _GUICtrlListBox_SetCurSel($List2, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile3) Then $sListData3 = FileRead($sListFile3) EndIf ; Load data read from the file GUICtrlSetData($List3, $sListData3) _GUICtrlListBox_SetCurSel($List3, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile4) Then $sListData4 = FileRead($sListFile4) EndIf ; Load data read from the file GUICtrlSetData($List4, $sListData4) _GUICtrlListBox_SetCurSel($List4, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile5) Then $sListData5 = FileRead($sListFile5) EndIf ; Load data read from the file GUICtrlSetData($List5, $sListData5) _GUICtrlListBox_SetCurSel($List5, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile6) Then $sListData6 = FileRead($sListFile6) EndIf ; Load data read from the file GUICtrlSetData($List6, $sListData6) _GUICtrlListBox_SetCurSel($List6, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile7) Then $sListData7 = FileRead($sListFile7) EndIf ; Load data read from the file GUICtrlSetData($List7, $sListData7) _GUICtrlListBox_SetCurSel($List7, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile8) Then $sListData8 = FileRead($sListFile8) EndIf ; Load data read from the file GUICtrlSetData($List8, $sListData8) _GUICtrlListBox_SetCurSel($List8, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile9) Then $sListData9 = FileRead($sListFile9) EndIf ; Load data read from the file GUICtrlSetData($List9, $sListData9) _GUICtrlListBox_SetCurSel($List9, $iIndex) ; Read saved file if it exists-------- If FileExists($sListFile10) Then $sListData10 = FileRead($sListFile10) EndIf EndFunc Func _pluseen($Button1) $iIndex += 1 _GUICtrlListBox_SetCurSel($List1, $iIndex) _GUICtrlListBox_SetCurSel($List4, $iIndex) EndFunc ; yes thank you, works great now!! I agree with the Openfile.txt it was kinda stupid, Thank you very much MHZ Link to comment Share on other sites More sharing options...
MHz Posted November 12, 2014 Share Posted November 12, 2014 I just noticed an issue of destroying a CtrlID on a review. In your loop, this case. Case $newitem $newitem = FileSaveDialog("Choose file...", @TempDir, "All (*.*)") Saving the result to $newitem is not advised as it is already used for the id of a created menu item in the gui. Something for you to fix. Link to comment Share on other sites More sharing options...
Arclite86 Posted November 13, 2014 Author Share Posted November 13, 2014 Question: When I want to create function do I always have to fill in the name of the case for example; Func _FillLists($file) This part ($file) because I have allot of case's that use the same function Link to comment Share on other sites More sharing options...
mikell Posted November 13, 2014 Share Posted November 13, 2014 Answer in post #39 BTW you are more and more confusing Help Forum and Help File Link to comment Share on other sites More sharing options...
Arclite86 Posted November 13, 2014 Author Share Posted November 13, 2014 Answer in post #39 BTW you are more and more confusing Help Forum and Help File thank you , I forgot about that 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