Jump to content

Critical end of the program when using @ GUI_CtrlId.


AndreyS
 Share

Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 Gude
How 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

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 by AndreyS
Link to comment
Share on other sites

  • Moderators

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
EndFunc
AutoIt's various checking tools cannot cover every eventuality - the coder must take some responsibilty for using the correct syntax. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

))) 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 by AndreyS
Link to comment
Share on other sites

  • Moderators

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:

#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 by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by Melba23
Merged posts
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by AndreyS
Link to comment
Share on other sites

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 Gude
How 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

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

  • Moderators

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. :whistle:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...