John-Paul Posted June 25, 2005 Posted June 25, 2005 (edited) I want to start a script and upon starting I want it to check for files (*.XLS, or CSV) in the current directory. If if finds any I want it to then list these in a menu item. I have so far the the very very basic steps..., this is only snippet CODE $GUI_CSVsMenu = GUICtrlCreateMenu ("&CSV Files") $GUI_CSVCheck = GUICtrlCreateMenuitem ("List" ,$GUI_CSVsMenu) CODE GUICtrlSetState($GUI_CSVCheck, GUI_DISABLE) Like i said its only in the idea stage. I wonder if anyone has already done this before or can help in getting this to a working solution. Once in the menu the user need only select any one of the listed files and it is opened in the script/app. jp Edited June 25, 2005 by John-Paul
ezzetabi Posted June 25, 2005 Posted June 25, 2005 hope it helps #include <GuiConstants.au3> Local $aFList = '', $sFiles, $hXls = FileFindFirstFile('*') While 1 $sFiles = FileFindNextFile($hXls) If @error Then FileClose($hXls) ExitLoop EndIf $aFList = $aFList & @LF & $sFiles WEnd $aFList = StringTrimLeft($aFList, 1) $aFList = StringSplit($aFList, @LF) GUICreate("MyGUI", 300, 300) Local $ctrlFileMenu = GUICtrlCreateMenu('Files') For $c = 1 To $aFList[0] $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu) Next GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ; EndSelect WEnd
John-Paul Posted June 25, 2005 Author Posted June 25, 2005 hope it helps#include <GuiConstants.au3> Local $aFList = '', $sFiles, $hXls = FileFindFirstFile('*') While 1 $sFiles = FileFindNextFile($hXls) If @error Then FileClose($hXls) ExitLoop EndIf $aFList = $aFList & @LF & $sFiles WEnd $aFList = StringTrimLeft($aFList, 1) $aFList = StringSplit($aFList, @LF) GUICreate("MyGUI", 300, 300) Local $ctrlFileMenu = GUICtrlCreateMenu('Files') For $c = 1 To $aFList[0] $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu) Next GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ; EndSelect WEnd<{POST_SNAPBACK}>This is exactly the bee's knee's.Thank you.jp
John-Paul Posted June 25, 2005 Author Posted June 25, 2005 hope it helpsFor $c = 1 To $aFList[0] $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu) Next GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ; EndSelect WEnd<{POST_SNAPBACK}>Not to be ungrateful can I seek your input into how to get it to select a listed file.The script is first class and works wonders, however when I get to the Case select I'm lost.CODECase $GUI_Msg = $GUI_CSVsMenuor as you usedGUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)I am completely lost, tried several versions of code I found in the forum but nothing picks up the listed files.There is a function called DoFileOpen($string) which will handle opening the selected file.I must also admit that I can't seem to get my head around arrays and so when I see 'For $c = 1 To $aFList[0]' I'm off with the ferries.Hope you can help.jp
HardCopy Posted June 25, 2005 Posted June 25, 2005 (edited) editing Edited June 25, 2005 by HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad
John-Paul Posted June 26, 2005 Author Posted June 26, 2005 editing<{POST_SNAPBACK}>Not sure what you mean, did I miss something.
gumby Posted June 26, 2005 Posted June 26, 2005 Hi, I'm trying to do the same and have got so far, but cannot get a response out of the goddam menu list.... arrghhh have u had any success with this?? If not can anyone out there help me pls! AutoIT rocks!! cheers
Zedna Posted June 26, 2005 Posted June 26, 2005 (edited) In main loop add this:GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else For $c = 1 To $aFList[0] If $msg = $aFList[$c] Then $menuitem = GUICtrlRead($aFList[$c],1) MsgBox(0, "Name of selected file", $menuitem[0]) ExitLoop EndIf Next EndSelect WEndAnd I recommend to call _ArraySort before showing menu:$aFList = StringSplit($aFList, @LF) _ArraySort($aFList,0,1); first position (number of items) must stay thereEdit: I was adding:- code to _ArraySort- ExitLoop after MsgBox() Edited June 26, 2005 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search
John-Paul Posted June 26, 2005 Author Posted June 26, 2005 In main loop add this:GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else For $c = 1 To $aFList[0] If $msg = $aFList[$c] Then $menuitem = GUICtrlRead($aFList[$c],1) MsgBox(0, "Name of selected file", $menuitem[0]) EndIf Next EndSelect WEndAnd I recommend to call _ArraySort before showing menu<{POST_SNAPBACK}>Thank you Zedna.Works perfectly and completes the whole process orginally provided by Ezzetabi and it now gives others a complete solution to use if they wish.As a thought to the forum, maybe a reference library with completed functional code could be a possibility for the future. I know its a job to manage such a resource so only a passing comment.The journey is also part of our growth and so we all have to crawl before we walk and I don't mean to take that away from anyone.Thanks.jp
gumby Posted June 28, 2005 Posted June 28, 2005 Thanks also, however i am have a few problems probably because i have oneventmode set to 1, so i am getting error messages regarding the GUICtrlRead($aFList[$c],1) saying that i have too may parameters and then again with the MsgBox....($menuitem[0]) part (something about a subscript on a nonarray variable).. Any further help would be very much appreciated as this is the first script I have written. many thanks Honor
John-Paul Posted June 28, 2005 Author Posted June 28, 2005 Thanks also, however i am have a few problems probably because i have oneventmode set to 1, so i am getting error messages regarding the GUICtrlRead($aFList[$c],1) saying that i have too may parameters and then again with the MsgBox....($menuitem[0]) part (something about a subscript on a nonarray variable).. Any further help would be very much appreciated as this is the first script I have written.many thanksHonor<{POST_SNAPBACK}>Just tested this and works perfectly, hope it helps.CODE#include <GuiConstants.au3>#include <Array.au3> ; Note to add thisLocal $aFList = '', $sFiles, $hXls = FileFindFirstFile('*') ; change to whatever you want could be *.xls or *.csvWhile 1 $sFiles = FileFindNextFile($hXls) If @error Then FileClose($hXls) ExitLoop EndIf $aFList = $aFList & @LF & $sFilesWEnd$aFList = StringTrimLeft($aFList, 1)$aFList = StringSplit($aFList, @LF)GUICreate("MyGUI", 300, 300)Local $ctrlFileMenu = GUICtrlCreateMenu('Files')For $c = 1 To $aFList[0] $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)NextGUISetState()While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else For $c = 1 To $aFList[0] If $msg = $aFList[$c] Then $menuitem = GUICtrlRead($aFList[$c],1) MsgBox(0, "Name of selected file", $menuitem[0]) ExitLoop EndIf Next EndSelectWEndWatch for text wrap.jp
Zedna Posted June 28, 2005 Posted June 28, 2005 Thanks also, however i am have a few problems probably because i have oneventmode set to 1, so i am getting error messages regarding the GUICtrlRead($aFList[$c],1) saying that i have too may parameters and then again with the MsgBox....($menuitem[0]) part (something about a subscript on a nonarray variable).. Any further help would be very much appreciated as this is the first script I have written.many thanksHonor<{POST_SNAPBACK}>You must use most recently beta version of AutoIt. Resources UDF ResourcesEx UDF AutoIt Forum Search
Zedna Posted June 28, 2005 Posted June 28, 2005 Just tested this and works perfectly, hope it helps.CODE#include <GuiConstants.au3>#include <Array.au3> ; Note to add thisLocal $aFList = '', $sFiles, $hXls = FileFindFirstFile('*') ; change to whatever you want could be *.xls or *.csvWhile 1 $sFiles = FileFindNextFile($hXls) If @error Then FileClose($hXls) ExitLoop EndIf $aFList = $aFList & @LF & $sFilesWEnd$aFList = StringTrimLeft($aFList, 1)$aFList = StringSplit($aFList, @LF)GUICreate("MyGUI", 300, 300)Local $ctrlFileMenu = GUICtrlCreateMenu('Files')For $c = 1 To $aFList[0] $aFList[$c] = GUICtrlCreateMenuItem($aFList[$c], $ctrlFileMenu)NextGUISetState()While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else For $c = 1 To $aFList[0] If $msg = $aFList[$c] Then $menuitem = GUICtrlRead($aFList[$c],1) MsgBox(0, "Name of selected file", $menuitem[0]) ExitLoop EndIf Next EndSelectWEndWatch for text wrap.jp<{POST_SNAPBACK}>Just add this and it will be done all:$aFList = StringSplit($aFList, @LF) _ArraySort($aFList,0,1); first position (number of items) must stay there Resources UDF ResourcesEx UDF AutoIt Forum Search
gumby Posted June 29, 2005 Posted June 29, 2005 Hi Zedna, ta again, by beta i presume you mean autoit-v3.1.1.55-bet.?? cheers
John-Paul Posted June 29, 2005 Author Posted June 29, 2005 (edited) Hi Zedna, ta again, by beta i presume you mean autoit-v3.1.1.55-bet.??cheers<{POST_SNAPBACK}>Not sure what version you have but Zedna's tweak works with v3.1.1.50 beta, have not tried ...55 yet.Edited: Here's the sample file that works with v3.1.1.50 beta_MenuListFiles.au3 Edited June 29, 2005 by John-Paul
gumby Posted June 29, 2005 Posted June 29, 2005 Hi JP, thanks, most of the code works fine with what i've got, its just the parts with the array variables, so i'll play around tonight and see if i can work it... I've also got to tweak it a little to go with the oneventmode being set to 1... anyway i'll also download the same version you have... cheers honor
Zedna Posted June 29, 2005 Posted June 29, 2005 I don't think beta 55 is needed but some new beta. If you have error like "toomany parametres" you have most probably old version... Resources UDF ResourcesEx UDF AutoIt Forum Search
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