Jump to content
Sign in to follow this  
Champak

Macro issue

Recommended Posts

Champak

I have a function that is called by a hotkey and onevent from a button and a combo box. In the function it looks for a specific button press with an IF condition by ways of the guicntrlID. If I hit the button, the function operates with no problem, if I then call the function with the hotkey any time after that there is no problem. The problem happens if I decide to access the function though the hotkey first before ever pressing the button. When I do that I get an error stating "unknown macro". This doesnt seem to make sense, Is this normal? What's the workaround?

Share this post


Link to post
Share on other sites
water

How should we know?

Give us more information! At least the source code!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Champak

I posted this off ipad. I thought it may be known already. Ill post something when i get on my computer later.

Share this post


Link to post
Share on other sites
water

In AutoIt macros are "variables" starting with @ like @Username. But Au3Check should post an error when it encounters an invalid macro before the script is started.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Champak

i made this here, but it should work.

#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)


HotKeySet("1", "_test")

guicreate("gui",300,300)

$button = GUICtrlCreateButton("button",50,50,100,100)
GUICtrlSetOnEvent($button,"_test")


$exit = GUICtrlCreateButton("exit",200,50,50,50)
GUICtrlSetOnEvent($exit,"_exit")
GUISetState()

while 1
    Sleep(100)
WEnd

    Func _test()
        If @GUI_CtrlId + $button Then
            MsgBox(0,0,"keypress")
        Else
            MsgBox(0,0,"hotset")
        EndIf
    EndFunc
Func _exit()
    Exit
    EndFunc

Share this post


Link to post
Share on other sites
water

Shouldn't this line

If @GUI_CtrlId + $button Then

be

If @GUI_CtrlId = $button Then

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

Champak,

From the Helpfile:

@GUI_CtrlId Last click GUI Control identifier. Only valid in an event Function. See the GUICtrlSetOnEvent() function

 

Apparently this is not set until a control is actioned.

Also, besides what water has pointed out, this

Else
            MsgBox(0,0,"hotset")

does not make sense as the script exits when the only other button is pressed.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Champak

It wasn't meant to make sense, just a quick extrapolation from memory of the overall situation to demonstrate. Now how do we fix this, because this doesn't make sense. What if I choose not to press the button. The macro should always be set once the app starts...in my opinion. Is there a way I can call/declare the macro on launch of the application without activating the function.

Share this post


Link to post
Share on other sites
water

Macros can not be set by a script - exceptions are @error and @extended which can be set by functions SetError and SetExtended.

I would let the hotkey call a different function. In this function set a variable e.g. $bHotKey = True and then call function _test. So you can tell if the button or the hotkey was pressed.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Champak

Thanks. Before I go the route of making another function, why can't I make a "SetMacro" function like the error functions. Where do I find that function to make changes to it if that's possible. Going the 2nd function route is going to create bloat in my app.

Share this post


Link to post
Share on other sites
water

My approach doesn't add too much code to your script:

Global $bHotKey = False
HotKeySet("1", "_TestHotKey")

Func _TestHotKey()
    $bHotKey = True
    _test()
EndFunc

Don't forget to reset $bHotKey when a button is pressed.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Champak

Thanks.

Share this post


Link to post
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
Sign in to follow this  

×