JustinReno Posted February 12, 2008 Share Posted February 12, 2008 I'm creating a program launcher, and this is my problem.. Throughout most scripts I've created, GUIGetMsg() seems to be ignored when its called in a For/Next loop: Anyway to solve this problem? Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) While 1 Switch GUIGetMsg() Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If GUIGetMsg() = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf Next WEnd Any help would be appreciated. Thanks. Link to comment Share on other sites More sharing options...
NELyon Posted February 12, 2008 Share Posted February 12, 2008 I'm creating a program launcher, and this is my problem.. Throughout most scripts I've created, GUIGetMsg() seems to be ignored when its called in a For/Next loop: Anyway to solve this problem? Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) While 1 Switch GUIGetMsg() Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If GUIGetMsg() = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf Next WEnd Any help would be appreciated. Thanks. Try saving GUIGetMsg into a variable before calling your For..Next loop. Link to comment Share on other sites More sharing options...
JustinReno Posted February 12, 2008 Author Share Posted February 12, 2008 I did, and it didn't work. . But thanks! Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 12, 2008 Moderators Share Posted February 12, 2008 You may be mis-interpreting what was suggested (as there was no example). You could just switch to OnEvent or you could use the suggested method of GUIGetMsg() Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) Global $myGUIMsg While 1 $myGUIMsg = GUIGetMsg() Switch $myGUIMsg Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If $myGUIMsg = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf Next WEndThis way you only poll the GUIGetMsg() once in a loop as it should be. (Note.. I didn't look at the script at all, just looked at your concern) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
NELyon Posted February 12, 2008 Share Posted February 12, 2008 You may be mis-interpreting what was suggested (as there was no example). You could just switch to OnEvent or you could use the suggested method of GUIGetMsg() Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) Global $myGUIMsg While 1 $myGUIMsg = GUIGetMsg() Switch $myGUIMsg Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If $myGUIMsg = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf Next WEndThis way you only poll the GUIGetMsg() once in a loop as it should be. (Note.. I didn't look at the script at all, just looked at your concern) Thanks Smoke. That's what i meant when i said that. Link to comment Share on other sites More sharing options...
JustinReno Posted February 12, 2008 Author Share Posted February 12, 2008 It didn't work... Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] Global $GUIMsg $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If $GUIMsg = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf Next WEnd Error: C:\Documents and Settings\Jar\Desktop\All organized Files\AutoIt\Autoit Scripts\Test.au3 (29) : ==> Unable to execute the external program.: If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) The system cannot find the file specified. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 12, 2008 Moderators Share Posted February 12, 2008 It didn't work... Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] Global $GUIMsg $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If $GUIMsg = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf Next WEndoÝ÷ ØJ뢰´÷`èréÛԶاÍ=Ø«ÓÝzÉ-¢=Ø e¢¸,ÞtX¥zÍ=Ø t÷`.¶IÊâ¦Û4÷dÞ²Ö®ßoIf the path has spaces in it, it's best to encase the path double quotes. Are you sure the path has the right "path" and "file name/extension"? Maybe use ShellExecute? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
JustinReno Posted February 12, 2008 Author Share Posted February 12, 2008 Well, this is how I wanted it to work: 1. Load a program into the program. 1A. It will write the program name and path into an ini and create a button for it. 2. When the user clicks that button, I want it to run the program's path that it finds in the ini. The For/Next loop checks to see if one of the buttons are clicked. But it seems to ignore the GuiGetMsg(). Link to comment Share on other sites More sharing options...
rasim Posted February 12, 2008 Share Posted February 12, 2008 Hi JustinReno!Try this example:expandcollapse popup#include <GuiConstants.au3> Opt("GuiOnEventMode", 1) Global $Ini = @ScriptDir & "\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [5, 30, 55, 80, 105, 130] $GUI = GUICreate("Program Launcher", 640, 480) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUICtrlSetOnEvent(-1, "ProgramAdd") GUISetState(@SW_SHOW, $GUI) While 1 Sleep(100) WEnd Func Quit() Exit EndFunc Func ProgramAdd() Local $GetProgramExecutable, $GetExecutableName $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") Return EndIf $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 10, $ButtonsPositionTop[$Count], 80 + StringLen($GetExecutableName[$GetExecutableName[0]]), 25) GUICtrlSetOnEvent(-1, "LaunchProgram") EndFunc Func LaunchProgram() Local $GetProgramPath $GetProgramPath = IniRead($Ini, "Programs", GUICtrlRead(@GUI_CtrlId), "None") If $GetProgramPath = "None" Then Return Run($GetProgramPath) EndFunc Link to comment Share on other sites More sharing options...
GEOSoft Posted February 12, 2008 Share Posted February 12, 2008 (edited) Well, this is how I wanted it to work: 1. Load a program into the program. 1A. It will write the program name and path into an ini and create a button for it. 2. When the user clicks that button, I want it to run the program's path that it finds in the ini. The For/Next loop checks to see if one of the buttons are clicked. But it seems to ignore the GuiGetMsg().$GetExecutableName = StringSplit($GetProgramExecutable, "\")Could be causing a problem. Add a message box just above the IniWrite() to see what $GetExecutableName[$GetExecutableName[0]] is being returned as. I think that is better as $GetExecutableName = StringMid($GetProgramExecutable, StringInStr($GetProgramExecutable, "\", 0, -1) +1) Also You might want to take a look at using $GetProgramExecutable = FileGetShortName(FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)")) Another thing about creating Dynamic Controls, always create them last and befor you create them do something like $BtnStart = GUICtrlCreateDummy() <Create your initial buttons here> $BtnEnd = GUICtrlCreateDummy() Then when you want to add another button 1) GUICtrlDelete($BtnEnd) 2) GUICtrlCreateButton(this is the new button) 3) Re-create $BtnEnd with $BtnEnd = GUICtrlCreateDummy() That will allow you to use Case $BtnStart +1 To $BtnEnd -1 Run (IniRead($Ini, "Programs", GUICtrlRead($Msg), "")) in your switch statement allowing you to eliminate the For Next which I think is causing your problem. Edit: For the sake of neatness and being able to increase the 5 button limit you might also want to consider changing the buttons to a combobox, list, listview or treeview control. In the event you use Listview or treeview then Create the Main control before the first dummy and the items between the 2 dummies as shown above. Edited February 12, 2008 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
JustinReno Posted February 12, 2008 Author Share Posted February 12, 2008 (edited) Thank you Rasim! Edit: And thanks GeoSoft. Edited February 12, 2008 by JustinReno Link to comment Share on other sites More sharing options...
Bowmore Posted February 12, 2008 Share Posted February 12, 2008 It didn't work... Global $Ini = @ScriptDir&"\Programs.ini" Global $Buttons[6], $Count = 1, $ButtonsPositionTop[6] = [0, 25, 50, 75, 100] Global $GUIMsg $GUI = GUICreate("Program Launcher", 640, 480) $Menu = GUICtrlCreateMenu("Configuration") $AddProgram = GUICtrlCreateMenuItem("Add Program", $Menu) GUISetState(@SW_SHOW, $GUI) While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case - 3 Exit Case $AddProgram $Count += 1 If $Count > 5 Then MsgBox(16, "Program Launcher", "Only 5 programs are allowed!") If $Count < 5 Then $GetProgramExecutable = FileOpenDialog("Program Launcher - Select Executable", @ScriptDir, "Exe(*.exe)") $GetExecutableName = StringSplit($GetProgramExecutable, "\") IniWrite($Ini, "Programs", $GetExecutableName[$GetExecutableName[0]], $GetProgramExecutable) $Buttons[$Count] = GUICtrlCreateButton($GetExecutableName[$GetExecutableName[0]], 0, $ButtonsPositionTop[$Count]) EndIf EndSwitch For $I = 1 To UBound($Buttons) - 1 If $GUIMsg = $Buttons[$I] Then $GetProgramPath = IniReadSection($Ini, "Programs") For $X = 1 To $GetProgramPath[0][0] If GUICtrlRead($Buttons[$I]) = $GetProgramPath[$I][0] Then Run($GetProgramPath[$I][1]) Next EndIf NextoÝ÷ ØíêZ¶Z²ÊZqë"+b·lmë-¶§q«¶©jØ]¢æåz«¨µë쨺˫zØ^¥«a«-êâjºijØjºZÖêº_W§jg¿{^Ȩ«¨·öÌk&ÞºÇéeº×¿ªê-y8^¦ºé°Øm+,yËb¢zr^Ëajܨ¹ªÞºÈ§Mú")Ú~ç{e¢m«n±ë4ߥڲØ^)r§µêÚºÚ"µÍQÜ ÌÍÒHHHÈPÝ[ ÌÍÐ]ÛÊHHBBRY ÌÍÑÕRSÙÈH ÌÍÐ]ÛÖÉÌÍÒWH[BBIÌÍÑÙ]ÙÜ[T]H[TXYÙXÝ[Û ÌÍÒ[K ][ÝÔÙÜ[É][ÝÊBBBQÜ ÌÍÖHHÈ ÌÍÑÙ]ÙÜ[T]ÌVÌBBBBRYÕRPÝXY ÌÍÐ]ÛÖÉÌÍÒWJHH ÌÍÑÙ]ÙÜ[T]ÉÌÍÒWVÌH[[ ÌÍÑÙ]ÙÜ[T]ÉÌÍÒWVÌWJBBBS^BQ[YS^oÝ÷ Øúèm¦åÊÈhºW[y«¢+Ø%½ÈÀÌØí$ôÄQ¼U ½Õ¹ ÀÌØí ÕÑѽ¹Ì¤´Ä($%%ÀÌØíU%5ÍôÀÌØí ÕÑѽ¹ÍlÀÌØí%tQ¡¸($$$ÀÌØíÑAɽɵAÑ ô%¹¥IMÑ¥½¸ ÀÌØí%¹¤°ÅÕ½ÐíAɽɵÌÅÕ½Ðì¤($$%½ÈÀÌØí`ôÄQ¼ÀÌØíÑAɽɵAÑ¡lÁulÁt($$$%%U% ÑɱI ÀÌØí ÕÑѽ¹ÍlÀÌØí%t¤ôÀÌØíÑAɽɵAÑ¡lÀÌØíaulÁtQ¡¸IÕ¸ ÀÌØíÑAɽɵAÑ¡lÀÌØíaulÅt¤($$%9áÐ($%¹%(%9áÐ "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook 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