AndreyS Posted August 15, 2013 Share Posted August 15, 2013 Found one fatal mistake. If you have not pressed any control, the condition: If @ GUI_CtrlId = $ Button1 Then ... leads to a critical conclusion of the program. Fix it in the next version of auto and when? And how to get around it now? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2013 Moderators Share Posted August 15, 2013 AndreyS,The GUI_CtrlId macro is only filled once a control has been actioned - it is designed to distinguish between controls that fire the same function. Can you post a reproducer script where you need to access this macro outside of an "Event fired" function? Then perhaps we can help you restructure your code to avoid the problem. 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...
Edano Posted August 15, 2013 Share Posted August 15, 2013 @ GUI_CtrlId is only used in on event mode in the event functions. it cannot fail, if properly scripted. [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
BrewManNH Posted August 15, 2013 Share Posted August 15, 2013 What error do you get, and does your script actually have those spaces between the @ and GUI_CtrlID, and between the $ and the word Button1? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
FireFox Posted August 15, 2013 Share Posted August 15, 2013 Well, the helpfile says "Only valid in an event Function." if it's called elsewhere don't be surprised it crashes. Link to comment Share on other sites More sharing options...
AndreyS Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) I understand that the code is meaningless, but nonetheless I Owned need a check in my real program. #include <Date.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $Form1=GUICreate("main", 200,200,100,100) $Time=GUICtrlCreateLabel("00:00",90,90) Dim $b1=GUICtrlCreateButton("Start",10,10) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") GUISetState(@SW_SHOW, $Form1) While 1 Sleep(2000) If @GUI_CtrlId=$b1 Then MsgBox(0,0,0) WEnd Func Quit() Exit EndFunc Edited August 15, 2013 by AndreyS Link to comment Share on other sites More sharing options...
FireFox Posted August 15, 2013 Share Posted August 15, 2013 Yeah, seems like the Au3Check does not check where is placed the macro. You can do this : ConsoleWrite(@GUI_CtrlId & @CrLf) But still, it's a useless check. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2013 Moderators Share Posted August 15, 2013 AndreyS,As has been explained above the macro is meaningless outside an "Event-fired" function. Recast your code into the correct syntax and it works as it should: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $Form1=GUICreate("main", 200,200,100,100) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Time=GUICtrlCreateLabel("00:00",90,90) $b1=GUICtrlCreateButton("Start",10,10) GUICtrlSetOnEvent($b1, "_Button") GUISetState(@SW_SHOW, $Form1) While 1 Sleep(10) WEnd Func _Button() MsgBox(0,0,0) EndFunc Func Quit() Exit EndFuncAutoIt's various checking tools cannot cover every eventuality - the coder must take some responsibilty for using the correct syntax. 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...
Edano Posted August 15, 2013 Share Posted August 15, 2013 you have on event mode, so the button must have guictrlsetonevent [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
AndreyS Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) ))) I know that this can be! But I need to check to check the function called it a combination of keys or buttons. The worst thing that the program falls out completely. (( If just returned an error. Edited August 15, 2013 by AndreyS Link to comment Share on other sites More sharing options...
AndreyS Posted August 15, 2013 Author Share Posted August 15, 2013 you have on event mode, so the button must have guictrlsetonevent I have a program running in both the interface and through the combination. A function I use the same. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2013 Moderators Share Posted August 15, 2013 (edited) AndreyS, Then you can check within the function like this: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $Form1=GUICreate("main", 200,200,100,100) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Time=GUICtrlCreateLabel("00:00",90,90) $b1=GUICtrlCreateButton("1",10,10) GUICtrlSetOnEvent($b1, "_Button") $b2=GUICtrlCreateButton("2",10,50) GUICtrlSetOnEvent($b2, "_Button") $b3=GUICtrlCreateButton("3",10,90) GUICtrlSetOnEvent($b3, "_Button") GUISetState(@SW_SHOW, $Form1) While 1 Sleep(10) WEnd Func _Button() Switch @GUI_CtrlId Case $b1 MsgBox(0,0,1) Case $b2 MsgBox(0,0,2) Case $b3 MsgBox(0,0,3) EndSwitch EndFunc Func Quit() Exit EndFunc Clear now? M23 Edit: I have just seen your edit above. If by "combination" you mean HotKey then you can do something like this: expandcollapse popup#include <GUIConstantsEx.au3> HotKeySet("^q", "_HotKey") Opt("GUIOnEventMode", 1) $Form1=GUICreate("main", 200,200,100,100) GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") $Time=GUICtrlCreateLabel("00:00",90,90) $b1=GUICtrlCreateButton("1",10,10) GUICtrlSetOnEvent($b1, "_Button") $b2=GUICtrlCreateButton("2",10,50) GUICtrlSetOnEvent($b2, "_Button") $b3=GUICtrlCreateButton("3",10,90) GUICtrlSetOnEvent($b3, "_Button") GUISetState(@SW_SHOW, $Form1) While 1 Sleep(10) WEnd Func _Function($iIndex) MsgBox(0, 0, $iIndex) EndFunc Func _HotKey() _Function(0) EndFunc Func _Button() Switch @GUI_CtrlId Case $b1 _Function(1) Case $b2 _Function(2) Case $b3 _Function(3) EndSwitch EndFunc Func Quit() Exit EndFunc Does that help? M23 Edited August 15, 2013 by Melba23 AndreyS 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...
AndreyS Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) It's not that. Function needs to check whether a button is pressed or a keyboard shortcut, and depending on it to carry out the following instructions. And it falls out when checking the condition.And whatever it was, should not such a simple condition leads to crash. Do you agree?Moreover, I know how to get around this error. But I know the importance fix it in future versions of AutoIt and when? My code will then become much easier. Edited August 15, 2013 by Melba23 Merged posts Link to comment Share on other sites More sharing options...
Edano Posted August 15, 2013 Share Posted August 15, 2013 AndreyS, believe me. there is nothing wrong with autoit. your code is wrong. [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2013 Moderators Share Posted August 15, 2013 AndreyS,Look at the edit I made to my post above - it shows how to use the same function when fired by a HotKey and controls. should not such a simple condition leads to crash. Do you agree?Not at all. In your example you are going against the Help file which clearly states: "@GUI_CtrlId Last click GUI Control identifier. Only valid in an event Function. See the GUICtrlSetOnEvent function"You can hardly expect AutoIt to fail gracefully when you so blatantly ignore the required syntax. fix it in future versions of AutoIt and when?Never. As I said, you cannot expect AutoIt to fail gracefully on every error - you have a responsibility to write code which respects the syntax rules as explained in the Help file. 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...
AndreyS Posted August 15, 2013 Author Share Posted August 15, 2013 (edited) As it turns out too many functions! It's uncomfortable. Function to function. Easier to use then there is a variable that will mean that indicating if the interface, or a combination of work and check it first. Here's what to me is really the ideal: #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $Form1=GUICreate("main", 200,200,100,100) Dim $b1=GUICtrlCreateButton("Start",10,10) HotKeySet("^q", "Msg") GUISetOnEvent($GUI_EVENT_CLOSE, "Quit") GUISetState(@SW_SHOW, $Form1) While 1 Sleep(2000) WEnd Func Msg() If @GUI_CtrlId=$b1 Then MsgBox(0,0,1) Else MsgBox(0,0,2) EndIf EndFunc Func Quit() Exit EndFunc Edited August 15, 2013 by AndreyS Link to comment Share on other sites More sharing options...
BrewManNH Posted August 15, 2013 Share Posted August 15, 2013 You have completely missed the point of what @GUI_CtrlID is supposed to be for. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AndreyS Posted August 15, 2013 Author Share Posted August 15, 2013 Yes, all I had realized that it does not work. But the problem would be if the variable returns an error and does not lead to collapse. It is not always the same, even working with the interface, I need to press the button first. And check if I have to press a button or any other way performed the action. Well thank you for nothing you all for the sympathy and help! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 15, 2013 Moderators Share Posted August 15, 2013 AndreyS,For the last time - AutoIt cannot do what you are trying to do and it is clearly stated in the Help file that such an approach is not possible. So stop complaining about AutoIt crashing when you ask it to run horribly incorrect, non-syntactic code and write your scripts correctly rather than seeking changes to elements which are perfectly well-understood and used correctly by everyone else. Well thank you for nothing you all for the sympathy and help!Not the best way to get help from us "all" in future - but on your head be it. 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...
Edano Posted August 15, 2013 Share Posted August 15, 2013 Well thank you for nothing . i can't believe it. [color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font] 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